diff options
5 files changed, 83 insertions, 6 deletions
diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java b/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java index f9e251fb6..893144ca9 100644 --- a/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java @@ -57,11 +57,11 @@ public class BuildProcess implements IBuildProcess { Assert.notNull(builders); for (IBuilder builder : builders) { if (builder == null) { - logger.error("builder is null"); + logger.debug("builder is null"); continue; } else { this.builders.add(builder); - logger.debug("{} builder was added.",builder.getClass().getName()); + logger.debug("{} builder was added.", builder.getClass().getName()); } } } diff --git a/org.tizen.common.packager/META-INF/MANIFEST.MF b/org.tizen.common.packager/META-INF/MANIFEST.MF index 7d6034316..7a23e2235 100644 --- a/org.tizen.common.packager/META-INF/MANIFEST.MF +++ b/org.tizen.common.packager/META-INF/MANIFEST.MF @@ -1,6 +1,6 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Tizen Packager +Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.tizen.common.packager Bundle-Version: 2.2.1.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.6 @@ -9,6 +9,7 @@ Export-Package: org.tizen.common.packager.core, Import-Package: org.eclipse.osgi.util, org.tizen.common.core.command, org.tizen.common.core.command.file, + org.tizen.common.core.command.policy, org.tizen.common.file, org.tizen.common.packager, org.tizen.common.sign.preferences, @@ -16,3 +17,5 @@ Import-Package: org.eclipse.osgi.util, org.tizen.common.sign.util, org.tizen.common.util, org.tizen.common.util.log +Require-Bundle: org.tizen.common +Bundle-Vendor: %Bundle-Vendor diff --git a/org.tizen.common.packager/OSGI-INF/l10n/bundle.properties b/org.tizen.common.packager/OSGI-INF/l10n/bundle.properties new file mode 100644 index 000000000..4d946128e --- /dev/null +++ b/org.tizen.common.packager/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +Bundle-Vendor = The Linux Foundation +Bundle-Name = Tizen Common Packager
\ No newline at end of file diff --git a/org.tizen.common.packager/src/org/tizen/common/packager/core/PackageCommand.java b/org.tizen.common.packager/src/org/tizen/common/packager/core/PackageCommand.java index 74f61c006..23da05c19 100644 --- a/org.tizen.common.packager/src/org/tizen/common/packager/core/PackageCommand.java +++ b/org.tizen.common.packager/src/org/tizen/common/packager/core/PackageCommand.java @@ -6,10 +6,19 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.core.command.CommandCancelException; import org.tizen.common.core.command.ExecutionContext; import org.tizen.common.core.command.Executor; +import org.tizen.common.core.command.Policy; import org.tizen.common.core.command.file.FileHandlingCommand; +import org.tizen.common.core.command.policy.OptionPolicy; +import org.tizen.common.core.command.prompter.FileHandlingOption; +import org.tizen.common.core.command.prompter.Option; +import org.tizen.common.core.command.prompter.RunnableOption; import org.tizen.common.file.FileHandler; import org.tizen.common.file.FileHandler.Attribute; import org.tizen.common.file.FileHandler.Type; @@ -31,11 +40,13 @@ import org.tizen.common.util.log.UserInteraction; import org.tizen.common.util.log.UserLogger; public class PackageCommand extends FileHandlingCommand<Boolean> { + Logger logger = LoggerFactory.getLogger(getClass()); private Collection<IResource> resources; private OutputStream outputStream = null; private boolean needSign; private String signPath; private String platformName; + private FileHandlingOption selectedAllFlagOption; public PackageCommand(Collection<IResource> resources, OutputStream os, boolean needSign, String signPath, String platformName) { Assert.notNull(resources); @@ -54,7 +65,7 @@ public class PackageCommand extends FileHandlingCommand<Boolean> { @Override public void run(Executor executor, ExecutionContext context) throws Exception { Assert.notNull(outputStream); - HashSet<IResource> packageResources = new HashSet<IResource>(); + List<IResource> packageResources = new ArrayList<IResource>(); for (IResource resource : resources) { if (filter.accept(resource.getFileHandler().getCurrentWorkingDirectory(), resource.getPath())) { @@ -67,10 +78,71 @@ public class PackageCommand extends FileHandlingCommand<Boolean> { } UserLogger.start( UserInteraction.CATE_WEB_PACKAGE, UserInteraction.BUILD_PACKAGING); - result = PackageUtil.createPackage(packageResources, outputStream); + result = PackageUtil.createPackage(handleDuplicateFile(packageResources, context), outputStream); UserLogger.end( UserInteraction.CATE_WEB_PACKAGE, UserInteraction.BUILD_PACKAGING); } + private Collection<IResource> handleDuplicateFile(List<IResource> packageResources, ExecutionContext context) { + if (packageResources == null + || packageResources.isEmpty()) { + return packageResources; + } + + Policy policy = context.getPolicy(Policy.EXIST_FILE_WHEN_COPY); + if(policy == null) + return packageResources; + OptionPolicy optionPolicy = policy.adapt( OptionPolicy.class ); + if ( null == optionPolicy ) + { + return packageResources; + } + Option[] options = optionPolicy.getOptions(); + for(Option option: options) { + if(!(option instanceof FileHandlingOption)) { + throw new IllegalArgumentException(String.format("Option %s is not a FileHandlingOption", option.getName())); + } + } + + List<IResource> resources = new ArrayList<IResource>(); + resources.addAll(packageResources); + + for (int i=0; i<packageResources.size(); i++) { + IResource packageResource = packageResources.get(i); + for (int j=i+1; j<packageResources.size(); j++) { + IResource duplicateResource = packageResources.get(j); + if (getDestPath(packageResource).equals(getDestPath(duplicateResource))) { + RunnableOption resultOption = null; + if(selectedAllFlagOption == null) { + String overwriteFilePath = FileUtil.appendPath(duplicateResource.getFileHandler().getCurrentWorkingDirectory(), getDestPath(duplicateResource)); + String question = "Resource exists in package. Do you wish to overwrite?\n\nOverwrite: "+ packageResource.getPath() +"\n\nwith: " + overwriteFilePath; + resultOption = (RunnableOption)context.getPrompter().interact(question, options); + } else { + resultOption = selectedAllFlagOption; + } + if(resultOption.isAllFlag()) { + selectedAllFlagOption = (FileHandlingOption) resultOption; + } + + if (resultOption.getName().startsWith("Overwrite")) { + resources.remove(packageResource); + } else if (resultOption.getName().startsWith("Ignore")) { + resources.remove(duplicateResource); + } else if (resultOption.getName().startsWith("Cancel")) { + throw new CommandCancelException(); + } + } + } + } + return resources; + } + + private String getDestPath(IResource resource) { + if (resource instanceof PackageResource) { + return ((PackageResource) resource).getDestination(); + } + return resource.getPath(); + } + private Collection<? extends IResource> generateSignResources(String savedSignTmpPath) throws Exception { UserLogger.start( UserInteraction.CATE_WEB_PACKAGE, UserInteraction.BUILD_SIGNING); diff --git a/org.tizen.common/src/org/tizen/common/util/PackageUtil.java b/org.tizen.common/src/org/tizen/common/util/PackageUtil.java index 0315aa452..efe0c8d26 100644 --- a/org.tizen.common/src/org/tizen/common/util/PackageUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/PackageUtil.java @@ -25,7 +25,7 @@ public class PackageUtil extends ZipUtil { * @return * @throws IOException */ - public static boolean createPackage(final HashSet<IResource> resources, OutputStream os) throws IOException { + public static boolean createPackage(final Collection<IResource> resources, OutputStream os) throws IOException { ZipOutputStream zos = null; InputStream content = null; ByteArrayInputStream bais = null; |