diff options
author | Pascal Rapicault | 2010-01-13 17:29:41 +0000 |
---|---|---|
committer | Pascal Rapicault | 2010-01-13 17:29:41 +0000 |
commit | 18189f0d42f7375660762dc6c885cf31683ae562 (patch) | |
tree | 17775d847bed9a33f3c68b74db2df75a2139c0bc /bundles/org.eclipse.equinox.p2.repository.tools | |
parent | c363f2984a09b73c422e38f4556fd3b23eafe958 (diff) | |
download | rt.equinox.p2-18189f0d42f7375660762dc6c885cf31683ae562.tar.gz rt.equinox.p2-18189f0d42f7375660762dc6c885cf31683ae562.tar.xz rt.equinox.p2-18189f0d42f7375660762dc6c885cf31683ae562.zip |
Merging api branch back to HEADv20100113
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository.tools')
90 files changed, 2848 insertions, 416 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/.classpath b/bundles/org.eclipse.equinox.p2.repository.tools/.classpath index 75116d75c..834ea833e 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/.classpath +++ b/bundles/org.eclipse.equinox.p2.repository.tools/.classpath @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry kind="src" output="bin_ant" path="src_ant"/> diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.p2.repository.tools/.settings/org.eclipse.jdt.core.prefs index 323ecbcd2..b07f19588 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/.settings/org.eclipse.jdt.core.prefs +++ b/bundles/org.eclipse.equinox.p2.repository.tools/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Fri Feb 27 09:31:49 EST 2009 +#Mon Dec 28 06:58:36 CET 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.builder.cleanOutputFolder=clean org.eclipse.jdt.core.builder.duplicateResourceTask=warning @@ -7,17 +7,17 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=jsr14 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.doc.comment.support=enabled org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning org.eclipse.jdt.core.compiler.problem.deadCode=warning @@ -26,13 +26,13 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled org.eclipse.jdt.core.compiler.problem.fieldHiding=warning org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore @@ -50,6 +50,7 @@ org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=enabled org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning @@ -88,7 +89,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 @@ -160,7 +161,6 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF index 1498ff596..1fc3ed3de 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF @@ -5,30 +5,45 @@ Bundle-SymbolicName: org.eclipse.equinox.p2.repository.tools;singleton:=true Bundle-Version: 1.0.100.qualifier Bundle-Activator: org.eclipse.equinox.p2.internal.repository.tools.Activator Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, - J2SE-1.4 -Import-Package: org.eclipse.equinox.app;version="1.0.0", - org.eclipse.equinox.internal.p2.artifact.mirror, +Bundle-RequiredExecutionEnvironment: J2SE-1.5, + J2SE-1.4, + CDC-1.1/Foundation-1.1 +Import-Package: org.eclipse.core.runtime;version="3.4.0", + org.eclipse.equinox.app;version="1.0.0", org.eclipse.equinox.internal.p2.artifact.repository, org.eclipse.equinox.internal.p2.artifact.repository.simple, org.eclipse.equinox.internal.p2.core.helpers, org.eclipse.equinox.internal.p2.director, org.eclipse.equinox.internal.p2.engine, + org.eclipse.equinox.internal.p2.engine.phases, + org.eclipse.equinox.internal.p2.metadata, + org.eclipse.equinox.internal.p2.metadata.query, org.eclipse.equinox.internal.p2.metadata.repository, + org.eclipse.equinox.internal.p2.persistence, org.eclipse.equinox.internal.p2.repository.helpers, - org.eclipse.equinox.internal.provisional.p2.artifact.repository, - org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing, org.eclipse.equinox.internal.provisional.p2.core, - org.eclipse.equinox.internal.provisional.p2.engine, - org.eclipse.equinox.internal.provisional.p2.engine.phases, + org.eclipse.equinox.internal.provisional.p2.director, org.eclipse.equinox.internal.provisional.p2.metadata, - org.eclipse.equinox.internal.provisional.p2.metadata.query, - org.eclipse.equinox.internal.provisional.p2.metadata.repository, - org.eclipse.equinox.internal.provisional.p2.repository, + org.eclipse.equinox.p2.core, + org.eclipse.equinox.p2.engine, + org.eclipse.equinox.p2.engine.spi, + org.eclipse.equinox.p2.metadata, + org.eclipse.equinox.p2.metadata.expression, + org.eclipse.equinox.p2.metadata.query, + org.eclipse.equinox.p2.query, + org.eclipse.equinox.p2.repository, + org.eclipse.equinox.p2.repository.artifact, + org.eclipse.equinox.p2.repository.artifact.spi, + org.eclipse.equinox.p2.repository.metadata, + org.eclipse.equinox.p2.repository.metadata.spi, org.eclipse.osgi.util;version="1.1.0", org.osgi.framework;version="1.4.0", org.osgi.service.packageadmin;version="1.2.0" Require-Bundle: org.eclipse.equinox.common;bundle-version="3.5.0" -Export-Package: org.eclipse.equinox.p2.internal.repository.tools;x-internal:=true +Export-Package: org.eclipse.equinox.p2.internal.repository.comparator;x-internal:=true, + org.eclipse.equinox.p2.internal.repository.mirroring;x-internal:=true, + org.eclipse.equinox.p2.internal.repository.tools;x-internal:=true, + org.eclipse.equinox.p2.internal.repository.tools.analyzer;x-internal:=true, + org.eclipse.equinox.p2.repository.tools.analyzer;x-internal:=true Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/build.properties b/bundles/org.eclipse.equinox.p2.repository.tools/build.properties index a1a83243a..bea6ebab2 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/build.properties +++ b/bundles/org.eclipse.equinox.p2.repository.tools/build.properties @@ -21,6 +21,7 @@ jars.compile.order = ., lib/repository-tools-ant.jar source.lib/repository-tools-ant.jar = src_ant/ output.lib/repository-tools-ant.jar = bin_ant/ jars.extra.classpath=platform:/plugin/org.apache.ant/lib/ant.jar,\ - platform:/plugin/org.eclipse.equinox.p2.jarprocessor/lib/jarprocessor-ant.jar,\ - platform:/plugin/org.eclipse.equinox.p2.artifact.repository/ant_tasks/artifactRepository-ant.jar + platform:/plugin/org.eclipse.equinox.p2.jarprocessor/lib/jarprocessor-ant.jar src.includes = about.html +javacTarget=jsr14 +javacSource=1.5 diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml b/bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml index 9cc4dc21d..db08b32e6 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml +++ b/bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml @@ -2,38 +2,112 @@ <?eclipse version="3.4"?> <plugin> - <extension - point="org.eclipse.ant.core.antTasks"> - <antTask - class="org.eclipse.equinox.p2.internal.repository.tools.tasks.Repo2RunnableTask" - library="lib/repository-tools-ant.jar" - name="p2.repo2runnable"> - </antTask> - - <antTask - class="org.eclipse.equinox.p2.internal.repository.tools.tasks.MirrorTask" - library="lib/repository-tools-ant.jar" - name="p2.mirror"> - </antTask> + <extension + point="org.eclipse.equinox.p2.repository.tools.verifier"> + <IUAnalysis + class="org.eclipse.equinox.p2.internal.repository.tools.analyzer.IUCounting" + name="IU Counting Tool"> + </IUAnalysis> + <IUAnalysis + class="org.eclipse.equinox.p2.internal.repository.tools.analyzer.CopyrightAnalyzer" + name="Copyright Analyzer"> + </IUAnalysis> + <IUAnalysis + class="org.eclipse.equinox.p2.internal.repository.tools.analyzer.LicenseAnalyzer" + name="License Analyzer"> + </IUAnalysis> + <IUAnalysis + class="org.eclipse.equinox.p2.internal.repository.tools.analyzer.HostCheckAnalyzer" + name="Fragment Host Analyzer"> + </IUAnalysis> + <IUAnalysis + class="org.eclipse.equinox.p2.internal.repository.tools.analyzer.UniqueIUAnalyzer" + name="Unique IU Analyzer"> + </IUAnalysis> + <IUAnalysis + class="org.eclipse.equinox.p2.internal.repository.tools.analyzer.UnzipFeatureJarAnalyzer" + name="Unzip Feature Jar Analyzer"> + </IUAnalysis> + <IUAnalysis + class="org.eclipse.equinox.p2.internal.repository.tools.analyzer.VersionAnalyzer" + name="Version Analyzer"> + </IUAnalysis> + </extension> + <extension-point id="org.eclipse.equinox.p2.repository.tools.verifier" name="Metadata Verifier" schema="schema/org.eclipse.equinox.p2.repository.tools.verifier.exsd"/> - <antTask - class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CompositeRepositoryTask" - library="lib/repository-tools-ant.jar" - name="p2.composite.repository"> - </antTask> - - <antTask + <extension point="org.eclipse.ant.core.antTasks"> + <antTask + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.Repo2RunnableTask" + library="lib/repository-tools-ant.jar" + name="p2.repo2runnable"> + </antTask> + + <antTask + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.MirrorTask" + library="lib/repository-tools-ant.jar" + name="p2.mirror"> + </antTask> + + <antTask + library="lib/repository-tools-ant.jar" + name="p2.artifact.mirror" + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.MirrorArtifactsTask"> + </antTask> + + <antTask + library="lib/repository-tools-ant.jar" + name="p2.metadata.mirror" + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.MirrorMetadataTask"> + </antTask> + + <antTask + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CompositeRepositoryTask" + library="lib/repository-tools-ant.jar" + name="p2.composite.repository"> + </antTask> + + <antTask library="lib/repository-tools-ant.jar" name="p2.process.artifacts" class="org.eclipse.equinox.p2.internal.repository.tools.tasks.ProcessRepoTask" > - </antTask> - - <antTask + </antTask> + + <antTask library="lib/repository-tools-ant.jar" name="p2.remove.iu" class="org.eclipse.equinox.p2.internal.repository.tools.tasks.RemoveIUTask" > - </antTask> - </extension> + </antTask> + + <antTask + library="lib/repository-tools-ant.jar" + name="p2.composite.artifact.repository.validate" + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.ValidateTask"> + </antTask> + + <antTask + library="lib/repository-tools-ant.jar" + name="p2.validate.artifacts" + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.ValidateTask"> + </antTask> + + <antTask + library="lib/repository-tools-ant.jar" + name="p2.composite.artifact.repository.add" + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CompositeRepositoryTask"> + </antTask> + + <antTask + library="lib/repository-tools-ant.jar" + name="p2.composite.artifact.repository.create" + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CreateCompositeArtifactRepositoryTask"> + </antTask> + + <antTask + library="lib/repository-tools-ant.jar" + name="p2.composite.artifact.repository.remove" + class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CompositeRepositoryTask"> + </antTask> + </extension> <extension id="org.eclipse.equinox.p2.repository.repo2runnable" @@ -43,12 +117,39 @@ </application> </extension> - <extension - point="org.eclipse.equinox.p2.artifact.repository.artifactComparators"> + <extension point="org.eclipse.equinox.p2.artifact.repository.artifactComparators"> + <artifactComparator + class="org.eclipse.equinox.p2.internal.repository.comparator.MD5ArtifactComparator" + id="org.eclipse.equinox.artifact.md5.comparator"> + </artifactComparator> + </extension> + <extension point="org.eclipse.equinox.p2.artifact.repository.artifactComparators"> <artifactComparator class="org.eclipse.equinox.p2.internal.repository.comparator.JarComparator" id="org.eclipse.equinox.p2.repository.tools.jar.comparator"> </artifactComparator> </extension> + + <extension id="org.eclipse.equinox.p2.repository.metadataverifier" point="org.eclipse.core.runtime.applications"> + <application cardinality="singleton-global" visible="true"> + <run class="org.eclipse.equinox.p2.internal.repository.tools.RepositoryAnalyzerApplication" /> + </application> + </extension> + + <extension id="org.eclipse.equinox.p2.artifact.repository.mirrorApplication" point="org.eclipse.core.runtime.applications"> + <application cardinality="1" thread="main" visible="true"> + <run class="org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication" > + <parameter name="metadataOrArtifacts" value="artifacts" /> + </run> + </application> + </extension> + + <extension id="org.eclipse.equinox.p2.metadata.repository.mirrorApplication" point="org.eclipse.core.runtime.applications"> + <application cardinality="1" thread="main" visible="true"> + <run class="org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication"> + <parameter name="metadataOrArtifacts" value="metadata" /> + </run> + </application> + </extension> </plugin> diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/schema/org.eclipse.equinox.p2.repository.tools.verifier.exsd b/bundles/org.eclipse.equinox.p2.repository.tools/schema/org.eclipse.equinox.p2.repository.tools.verifier.exsd new file mode 100644 index 000000000..ba2d23b96 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/schema/org.eclipse.equinox.p2.repository.tools.verifier.exsd @@ -0,0 +1,109 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.equinox.p2.repository.tools" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appinfo> + <meta.schema plugin="org.eclipse.equinox.p2.repository.tools" id="org.eclipse.equinox.p2.repository.tools.verifier" name="Metadata Verifier"/> + </appinfo> + <documentation> + [Enter description of this extension point.] + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appinfo> + <meta.element /> + </appinfo> + </annotation> + <complexType> + <sequence minOccurs="0" maxOccurs="unbounded"> + <element ref="IUAnalysis"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute translatable="true"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="IUAnalysis"> + <complexType> + <attribute name="class" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn=":org.eclipse.equinox.p2.metadata.analyzer.IIUAnalysis"/> + </appinfo> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appinfo> + <meta.section type="since"/> + </appinfo> + <documentation> + [Enter the first release in which this extension point appears.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="examples"/> + </appinfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="apiinfo"/> + </appinfo> + <documentation> + [Enter API information here.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="implementation"/> + </appinfo> + <documentation> + [Enter information about supplied implementation of this extension point.] + </documentation> + </annotation> + + +</schema> diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/JarComparator.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/JarComparator.java index 5dbb891bc..7d2b7de43 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/JarComparator.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/JarComparator.java @@ -10,13 +10,19 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.comparator; +import org.eclipse.equinox.p2.internal.repository.comparator.java.*; + +import org.eclipse.equinox.p2.repository.tools.comparator.IArtifactComparator; + import java.io.*; import java.util.*; +import java.util.Map.Entry; import java.util.jar.*; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.osgi.util.NLS; public class JarComparator implements IArtifactComparator { @@ -80,8 +86,8 @@ public class JarComparator implements IArtifactComparator { if (firstFileSize != secondFileSize) { return newErrorStatus(NLS.bind(Messages.differentNumberOfEntries, new String[] {descriptorString, sourceLocation, Integer.toString(firstFileSize), destinationLocation, Integer.toString(secondFileSize)})); } - for (Enumeration enumeration = firstFile.entries(); enumeration.hasMoreElements();) { - ZipEntry entry = (ZipEntry) enumeration.nextElement(); + for (Enumeration<? extends ZipEntry> enumeration = firstFile.entries(); enumeration.hasMoreElements();) { + ZipEntry entry = enumeration.nextElement(); String entryName = entry.getName(); final ZipEntry entry2 = secondFile.getEntry(entryName); if (!entry.isDirectory() && entry2 != null) { @@ -145,8 +151,7 @@ public class JarComparator implements IArtifactComparator { Attributes attributes2 = manifest2.getMainAttributes(); if (attributes.size() != attributes2.size()) return false; - for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) { - Map.Entry entry = (Map.Entry) iterator.next(); + for (Entry<Object, Object> entry : attributes.entrySet()) { Object value2 = attributes2.get(entry.getKey()); if (value2 == null) { return false; @@ -192,7 +197,7 @@ public class JarComparator implements IArtifactComparator { return false; props1.keys(); - for (Iterator iterator = props1.keySet().iterator(); iterator.hasNext();) { + for (Iterator<Object> iterator = props1.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); if (!props2.containsKey(key)) return false; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/MD5ArtifactComparator.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/MD5ArtifactComparator.java new file mode 100644 index 000000000..754aeb22e --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/MD5ArtifactComparator.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.p2.internal.repository.comparator; + +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.artifact.repository.Activator; +import org.eclipse.equinox.p2.internal.repository.tools.Messages; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.tools.comparator.IArtifactComparator; +import org.eclipse.osgi.util.NLS; + +public class MD5ArtifactComparator implements IArtifactComparator { + + public static String MD5_COMPARATOR_ID = "org.eclipse.equinox.artifact.md5.comparator"; //$NON-NLS-1$ + + public IStatus compare(IArtifactRepository source, IArtifactDescriptor sourceDescriptor, IArtifactRepository destination, IArtifactDescriptor destDescriptor) { + String sourceMD5 = sourceDescriptor.getProperty(IArtifactDescriptor.DOWNLOAD_MD5); + String destMD5 = destDescriptor.getProperty(IArtifactDescriptor.DOWNLOAD_MD5); + + if (sourceMD5 == null && destMD5 == null) + return new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.info_noMD5Infomation, sourceDescriptor)); + + if (sourceMD5 == null) + return new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.info_noMD5InRepository, source, sourceDescriptor)); + + if (destMD5 == null) + return new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.info_noMD5InRepository, destination, destDescriptor)); + + if (sourceMD5.equals(destMD5)) + return Status.OK_STATUS; + + return new Status(IStatus.WARNING, Activator.ID, NLS.bind(Messages.warning_differentMD5, new Object[] {URIUtil.toUnencodedString(sourceDescriptor.getRepository().getLocation()), URIUtil.toUnencodedString(destDescriptor.getRepository().getLocation()), sourceDescriptor})); + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Annotation.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Annotation.java index 2771ea6f1..db3fea4ce 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Annotation.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Annotation.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class Annotation extends ClassFileStruct { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/AnnotationComponent.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/AnnotationComponent.java index ac8374398..7a1922d3b 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/AnnotationComponent.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/AnnotationComponent.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class AnnotationComponent extends ClassFileStruct { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/AnnotationComponentValue.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/AnnotationComponentValue.java index 386643914..74a26447c 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/AnnotationComponentValue.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/AnnotationComponentValue.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class AnnotationComponentValue extends ClassFileStruct { /** diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/AnnotationDefaultAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/AnnotationDefaultAttribute.java index a52692c20..638adb12d 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/AnnotationDefaultAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/AnnotationDefaultAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class AnnotationDefaultAttribute extends ClassFileAttribute { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/AttributeNamesConstants.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/AttributeNamesConstants.java index 3f55bfce0..f4d03fcc7 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/AttributeNamesConstants.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/AttributeNamesConstants.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public interface AttributeNamesConstants { /* diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/CharOperation.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/CharOperation.java index 2f1ae4d9b..246c66dbc 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/CharOperation.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/CharOperation.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public final class CharOperation { public static final char[] This = "this".toCharArray(); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ClassFileAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ClassFileAttribute.java index 05225801f..bcc92e718 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ClassFileAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ClassFileAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class ClassFileAttribute extends ClassFileStruct { public static final ClassFileAttribute[] NO_ATTRIBUTES = new ClassFileAttribute[0]; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ClassFileReader.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ClassFileReader.java index 61765ef09..dea13cc34 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ClassFileReader.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ClassFileReader.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; import java.util.Arrays; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ClassFileStruct.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ClassFileStruct.java index a8c6038e3..24e4f6493 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ClassFileStruct.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ClassFileStruct.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public abstract class ClassFileStruct { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ClassFormatException.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ClassFormatException.java index acff39c2c..32d05426f 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ClassFormatException.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ClassFormatException.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class ClassFormatException extends Exception { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/CodeAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/CodeAttribute.java index 97884685a..70f5f3dc2 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/CodeAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/CodeAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class CodeAttribute extends ClassFileAttribute { private static final ExceptionTableEntry[] NO_EXCEPTION_TABLE = new ExceptionTableEntry[0]; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ConstantPool.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ConstantPool.java index 380108600..a6c585ab2 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ConstantPool.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ConstantPool.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class ConstantPool extends ClassFileStruct { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ConstantPoolConstant.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ConstantPoolConstant.java index 7cebf66e1..abc13b255 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ConstantPoolConstant.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ConstantPoolConstant.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public interface ConstantPoolConstant { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ConstantPoolEntry.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ConstantPoolEntry.java index cdee2fd49..881356fce 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ConstantPoolEntry.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ConstantPoolEntry.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class ConstantPoolEntry { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ConstantValueAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ConstantValueAttribute.java index 75e961e77..cfc20ec56 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ConstantValueAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ConstantValueAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class ConstantValueAttribute extends ClassFileAttribute { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/DefaultBytecodeVisitor.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/DefaultBytecodeVisitor.java index aaeaf264b..90b8599a3 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/DefaultBytecodeVisitor.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/DefaultBytecodeVisitor.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; import org.eclipse.osgi.util.NLS; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Disassembler.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Disassembler.java index f96d48823..69a9bfb3c 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Disassembler.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Disassembler.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; import java.util.Arrays; import java.util.Comparator; @@ -1040,10 +1040,8 @@ public class Disassembler { private void disassembleTypeMembers(ClassFileReader classFileReader, char[] className, StringBuffer buffer, String lineSeparator, int tabNumber, int mode, boolean isEnum) { FieldInfo[] fields = classFileReader.getFieldInfos(); // sort fields - Arrays.sort(fields, new Comparator() { - public int compare(Object o1, Object o2) { - FieldInfo fieldInfo1 = (FieldInfo) o1; - FieldInfo fieldInfo2 = (FieldInfo) o2; + Arrays.sort(fields, new Comparator<FieldInfo>() { + public int compare(FieldInfo fieldInfo1, FieldInfo fieldInfo2) { int compare = new String(fieldInfo1.getName()).compareTo(new String(fieldInfo2.getName())); if (compare == 0) { return new String(fieldInfo1.getDescriptor()).compareTo(new String(fieldInfo2.getDescriptor())); @@ -1057,10 +1055,8 @@ public class Disassembler { } MethodInfo[] methods = classFileReader.getMethodInfos(); // sort methods - Arrays.sort(methods, new Comparator() { - public int compare(Object o1, Object o2) { - MethodInfo methodInfo1 = (MethodInfo) o1; - MethodInfo methodInfo2 = (MethodInfo) o2; + Arrays.sort(methods, new Comparator<MethodInfo>() { + public int compare(MethodInfo methodInfo1, MethodInfo methodInfo2) { int compare = new String(methodInfo1.getName()).compareTo(new String(methodInfo2.getName())); if (compare == 0) { return new String(methodInfo1.getDescriptor()).compareTo(new String(methodInfo2.getDescriptor())); diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/EnclosingMethodAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/EnclosingMethodAttribute.java index f764778fb..a7daac77d 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/EnclosingMethodAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/EnclosingMethodAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class EnclosingMethodAttribute extends ClassFileAttribute { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ExceptionAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ExceptionAttribute.java index 336aae015..7883c093a 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ExceptionAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ExceptionAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class ExceptionAttribute extends ClassFileAttribute { private int exceptionsNumber; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ExceptionTableEntry.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ExceptionTableEntry.java index 6d889cd27..0598acf2a 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ExceptionTableEntry.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ExceptionTableEntry.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class ExceptionTableEntry extends ClassFileStruct { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/FieldInfo.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/FieldInfo.java index 9ebd6a86d..46b79c64d 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/FieldInfo.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/FieldInfo.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; import java.util.Arrays; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/IModifierConstants.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/IModifierConstants.java index 17607b11e..b869fdbc1 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/IModifierConstants.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/IModifierConstants.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public interface IModifierConstants { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/IOpcodeMnemonics.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/IOpcodeMnemonics.java index 720591ed6..a6de65d6b 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/IOpcodeMnemonics.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/IOpcodeMnemonics.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public interface IOpcodeMnemonics { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/InnerClassesAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/InnerClassesAttribute.java index 4a316098b..a9202fe72 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/InnerClassesAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/InnerClassesAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class InnerClassesAttribute extends ClassFileAttribute { private static final InnerClassesAttributeEntry[] NO_ENTRIES = new InnerClassesAttributeEntry[0]; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/InnerClassesAttributeEntry.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/InnerClassesAttributeEntry.java index 34b267fb2..2c63c8a44 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/InnerClassesAttributeEntry.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/InnerClassesAttributeEntry.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class InnerClassesAttributeEntry extends ClassFileStruct { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Messages.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Messages.java index 3edd78f26..8c2076f23 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Messages.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Messages.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; import org.eclipse.osgi.util.NLS; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/MethodInfo.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/MethodInfo.java index c7789475a..14d57c21b 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/MethodInfo.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/MethodInfo.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; import java.util.Arrays; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/OpcodeStringValues.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/OpcodeStringValues.java index 76f80e9b6..dbc879e9b 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/OpcodeStringValues.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/OpcodeStringValues.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class OpcodeStringValues implements IOpcodeMnemonics { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ParameterAnnotation.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ParameterAnnotation.java index ad7c6dcac..8f08991c1 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/ParameterAnnotation.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/ParameterAnnotation.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class ParameterAnnotation extends ClassFileStruct { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/RuntimeInvisibleAnnotationsAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/RuntimeInvisibleAnnotationsAttribute.java index f2e164c79..ef3244b5d 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/RuntimeInvisibleAnnotationsAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/RuntimeInvisibleAnnotationsAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class RuntimeInvisibleAnnotationsAttribute extends ClassFileAttribute { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/RuntimeInvisibleParameterAnnotationsAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/RuntimeInvisibleParameterAnnotationsAttribute.java index 3c724dd08..b9f489153 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/RuntimeInvisibleParameterAnnotationsAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/RuntimeInvisibleParameterAnnotationsAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class RuntimeInvisibleParameterAnnotationsAttribute extends ClassFileAttribute { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/RuntimeVisibleAnnotationsAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/RuntimeVisibleAnnotationsAttribute.java index ff738fa3c..00306e271 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/RuntimeVisibleAnnotationsAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/RuntimeVisibleAnnotationsAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class RuntimeVisibleAnnotationsAttribute extends ClassFileAttribute { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/RuntimeVisibleParameterAnnotationsAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/RuntimeVisibleParameterAnnotationsAttribute.java index 71700e217..1f2b84011 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/RuntimeVisibleParameterAnnotationsAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/RuntimeVisibleParameterAnnotationsAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class RuntimeVisibleParameterAnnotationsAttribute extends ClassFileAttribute { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Signature.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Signature.java index e530f1e40..7b855bb25 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Signature.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Signature.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; import java.util.ArrayList; @@ -577,7 +577,7 @@ public final class Signature { if (methodOrTypeSignature[0] != C_GENERIC_START) return CharOperation.NO_CHAR_CHAR; - ArrayList paramList = new ArrayList(1); + ArrayList<char[]> paramList = new ArrayList<char[]>(1); int paramStart = 1, i = 1; // start after leading '<' while (i < length) { if (methodOrTypeSignature[i] == C_GENERIC_END) { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/SignatureAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/SignatureAttribute.java index e6024103a..f186ca661 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/SignatureAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/SignatureAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class SignatureAttribute extends ClassFileAttribute { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/SourceFileAttribute.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/SourceFileAttribute.java index f468e8433..1d51be982 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/SourceFileAttribute.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/SourceFileAttribute.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public class SourceFileAttribute extends ClassFileAttribute { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/TypeConstants.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/TypeConstants.java index 1e000fbd9..99e3e7841 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/TypeConstants.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/TypeConstants.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; public interface TypeConstants { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Utility.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Utility.java index 888ce1654..4a982deb4 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/Utility.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Utility.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.internal.repository.comparator; +package org.eclipse.equinox.p2.internal.repository.comparator.java; import java.io.*; import java.util.Arrays; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/messages.properties b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/messages.properties index e8c395639..e8c395639 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/messages.properties +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/messages.properties diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/FileMirrorLog.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/FileMirrorLog.java new file mode 100644 index 000000000..8ea5bfa04 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/FileMirrorLog.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.mirroring; + +import java.io.*; +import java.util.Date; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.artifact.repository.Messages; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; + +public class FileMirrorLog implements IArtifactMirrorLog { + + private static final String INDENT = "\t"; //$NON-NLS-1$ + private static final String SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$ + private BufferedWriter out; + private boolean consoleMessage = false; + private int minSeverity = IStatus.OK; + private boolean hasRoot = false; + + public FileMirrorLog(String location, int minSeverity, String root) { + this.minSeverity = minSeverity; + try { + File log = new File(location); + if (log.getParentFile().exists() || log.getParentFile().mkdirs()) { + out = new BufferedWriter(new FileWriter(log, true)); + if (root != null) { + log(root + " - " + new Date()); //$NON-NLS-1$ + hasRoot = true; + } + } else + throw new IOException(Messages.exception_unableToCreateParentDir); + } catch (IOException e) { + exceptionOccurred(null, e); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#log(org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor, org.eclipse.core.runtime.IStatus) + */ + public void log(IArtifactDescriptor descriptor, IStatus status) { + if (status.getSeverity() >= minSeverity) { + log(descriptor.toString()); + log(status, INDENT); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#log(org.eclipse.core.runtime.IStatus) + */ + public void log(IStatus status) { + log(status, ""); //$NON-NLS-1$ + } + + /* + * Write a status to the log, indenting it based on status depth. + * @param status the status to log + * @param depth the depth of the status + */ + private void log(IStatus status, String prefix) { + if (status.getSeverity() >= minSeverity) { + // Write status to log + log(prefix + status.getMessage()); + + // Write exception to log if applicable + String exceptionMessage = status.getException() != null ? status.getException().getMessage() : null; + if (exceptionMessage != null) + log(prefix + exceptionMessage); + + // Write the children of the status to the log + IStatus[] nestedStatus = status.getChildren(); + if (nestedStatus != null) + for (int i = 0; i < nestedStatus.length; i++) + log(nestedStatus[i], prefix + INDENT); + } + } + + /* + * Write a message to the log + * @param message the message to write + */ + private void log(String message) { + try { + out.write((hasRoot ? INDENT : "") + message + SEPARATOR); //$NON-NLS-1$ + } catch (IOException e) { + exceptionOccurred((hasRoot ? INDENT : "") + message, e); //$NON-NLS-1$ + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#close() + */ + public void close() { + try { + if (out != null) + out.close(); + } catch (IOException e) { + exceptionOccurred(null, e); + } + } + + /* + * Show an error message if this the first time, and print status messages. + */ + private void exceptionOccurred(String message, Exception e) { + if (!consoleMessage) { + System.err.println(Messages.MirrorLog_Exception_Occurred); + e.printStackTrace(System.err); + System.err.println(Messages.MirrorLog_Console_Log); + consoleMessage = true; + } + if (message != null) + System.out.println(message); + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/IArtifactMirrorLog.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/IArtifactMirrorLog.java new file mode 100644 index 000000000..727929df5 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/IArtifactMirrorLog.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.mirroring; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; + +public interface IArtifactMirrorLog { + + // Log a status associated with a descriptor + public void log(IArtifactDescriptor descriptor, IStatus status); + + // Log a status + public void log(IStatus status); + + // Notify that logging is completed & cleanup resources + public void close(); +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/Mirroring.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/Mirroring.java new file mode 100644 index 000000000..8d2b993ad --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/Mirroring.java @@ -0,0 +1,291 @@ +/******************************************************************************* + * Copyright (c) 2007, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Compeople AG (Stefan Liebig) - various ongoing maintenance + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.mirroring; + +import org.eclipse.equinox.p2.repository.tools.comparator.ArtifactComparatorFactory; +import org.eclipse.equinox.p2.repository.tools.comparator.IArtifactComparator; + +import java.util.*; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.artifact.repository.RawMirrorRequest; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.internal.repository.tools.Activator; +import org.eclipse.equinox.p2.internal.repository.tools.Messages; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.repository.artifact.*; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; +import org.eclipse.osgi.util.NLS; + +/** + * A utility class that performs mirroring of artifacts between repositories. + */ +public class Mirroring { + private IArtifactRepository source; + private IArtifactRepository destination; + private IArtifactRepository baseline; + private boolean raw; + private boolean compare = false; + private boolean validate = false; + private IArtifactComparator comparator; + private String comparatorID; + private List<IArtifactKey> keysToMirror; + private IArtifactMirrorLog comparatorLog; + + private IArtifactComparator getComparator() { + if (comparator == null) + comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); + return comparator; + } + + public Mirroring(IArtifactRepository source, IArtifactRepository destination, boolean raw) { + this.source = source; + this.destination = destination; + this.raw = raw; + } + + public void setCompare(boolean compare) { + this.compare = compare; + } + + public void setComparatorId(String id) { + this.comparatorID = id; + } + + public void setComparatorLog(IArtifactMirrorLog comparatorLog) { + this.comparatorLog = comparatorLog; + } + + public void setBaseline(IArtifactRepository baseline) { + this.baseline = baseline; + } + + public void setValidate(boolean validate) { + this.validate = validate; + } + + public MultiStatus run(boolean failOnError, boolean verbose) { + if (!destination.isModifiable()) + throw new IllegalStateException(NLS.bind(Messages.exception_destinationNotModifiable, destination.getLocation())); + if (compare) + getComparator(); //initialize the comparator. Only needed if we're comparing. Used to force error if comparatorID is invalid. + MultiStatus multiStatus = new MultiStatus(Activator.ID, IStatus.OK, Messages.message_mirroringStatus, null); + Iterator<IArtifactKey> keys = null; + if (keysToMirror != null) + keys = keysToMirror.iterator(); + else { + IQueryResult<IArtifactKey> result = source.query(ArtifactKeyQuery.ALL_KEYS, null); + keys = result.iterator(); + } + while (keys.hasNext()) { + IArtifactKey key = keys.next(); + IArtifactDescriptor[] descriptors = source.getArtifactDescriptors(key); + for (int j = 0; j < descriptors.length; j++) { + IStatus result = mirror(descriptors[j], verbose); + //Only log INFO and WARNING if we want verbose logging. Always log ERRORs + if (!result.isOK() && (verbose || result.getSeverity() == IStatus.ERROR)) + multiStatus.add(result); + //stop mirroring as soon as we have an error + if (failOnError && multiStatus.getSeverity() == IStatus.ERROR) + return multiStatus; + } + } + if (validate) { + // Simple validation of the mirror + IStatus validation = validateMirror(verbose); + if (!validation.isOK() && (verbose || validation.getSeverity() == IStatus.ERROR)) + multiStatus.add(validation); + } + return multiStatus; + } + + private IStatus mirror(IArtifactDescriptor descriptor, boolean verbose) { + IArtifactDescriptor newDescriptor = raw ? descriptor : new ArtifactDescriptor(descriptor); + + if (verbose) + System.out.println("Mirroring: " + descriptor.getArtifactKey() + " (Descriptor: " + descriptor + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + if (compare && baseline != null) + if (baseline.contains(descriptor)) { + // we have to create an output stream based on the descriptor found in the baseline otherwise all + // the properties will be copied over from the wrong descriptor and our repository will be inconsistent. + IArtifactDescriptor baselineDescriptor = getBaselineDescriptor(descriptor); + + // if we found a descriptor in the baseline then we'll use it to copy the artifact + if (baselineDescriptor != null) { + MultiStatus status = new MultiStatus(Activator.ID, IStatus.OK, NLS.bind(Messages.Mirroring_compareAndDownload, descriptor), null); + //Compare source against baseline + IStatus comparison = getComparator().compare(baseline, baselineDescriptor, source, descriptor); + if (comparatorLog != null) + comparatorLog.log(baselineDescriptor, comparison); + status.add(comparison); + if (destination.contains(baselineDescriptor)) + return compareToDestination(baselineDescriptor); + + //download artifact from baseline + status.add(downloadArtifact(baseline, baselineDescriptor, baselineDescriptor)); + return status; + } + } + + // Check if the destination already contains the file. + if (destination.contains(newDescriptor)) { + if (compare) + return compareToDestination(descriptor); + String message = NLS.bind(Messages.mirror_alreadyExists, descriptor, destination); + return new Status(IStatus.INFO, Activator.ID, ProvisionException.ARTIFACT_EXISTS, message, null); + } + + return downloadArtifact(source, newDescriptor, descriptor); + } + + /** + * Takes an IArtifactDescriptor descriptor and the ProvisionException that was thrown when destination.getOutputStream(descriptor) + * and compares descriptor to the duplicate descriptor in the destination. + * + * Callers should verify the ProvisionException was thrown due to the artifact existing in the destination before invoking this method. + * @param descriptor + * @return the status of the compare + */ + private IStatus compareToDestination(IArtifactDescriptor descriptor) { + IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(descriptor.getArtifactKey()); + IArtifactDescriptor destDescriptor = null; + for (int i = 0; destDescriptor == null && i < destDescriptors.length; i++) { + if (destDescriptors[i].equals(descriptor)) + destDescriptor = destDescriptors[i]; + } + if (destDescriptor == null) + return new Status(IStatus.INFO, Activator.ID, ProvisionException.ARTIFACT_EXISTS, Messages.Mirroring_noMatchingDescriptor, null); + return compare(source, descriptor, destination, destDescriptor); + } + + private IStatus compare(IArtifactRepository sourceRepository, IArtifactDescriptor sourceDescriptor, IArtifactRepository destRepository, IArtifactDescriptor destDescriptor) { + IStatus comparison = getComparator().compare(sourceRepository, sourceDescriptor, destRepository, destDescriptor); + if (comparatorLog != null) + comparatorLog.log(sourceDescriptor, comparison); + return comparison; + } + + /* + * Create, and execute a MirrorRequest for a given descriptor. + */ + private IStatus downloadArtifact(IArtifactRepository sourceRepo, IArtifactDescriptor destDescriptor, IArtifactDescriptor srcDescriptor) { + RawMirrorRequest request = new RawMirrorRequest(srcDescriptor, destDescriptor, destination); + request.setSourceRepository(sourceRepo); + + request.perform(new NullProgressMonitor()); + + return request.getResult(); + } + + public void setArtifactKeys(IArtifactKey[] keys) { + this.keysToMirror = Arrays.asList(keys); + } + + /* + * Get the equivalent descriptor from the baseline repository + */ + private IArtifactDescriptor getBaselineDescriptor(IArtifactDescriptor descriptor) { + IArtifactDescriptor[] baselineDescriptors = baseline.getArtifactDescriptors(descriptor.getArtifactKey()); + for (int i = 0; i < baselineDescriptors.length; i++) { + if (baselineDescriptors[i].equals(descriptor)) + return baselineDescriptors[i]; + } + return null; + } + + /* + * Simple validation of a mirror to see if all source descriptors are present in the destination + */ + private IStatus validateMirror(boolean verbose) { + MultiStatus status = new MultiStatus(Activator.ID, 0, Messages.Mirroring_ValidationError, null); + + // The keys that were mirrored in this session + Iterator<IArtifactKey> keys = null; + if (keysToMirror != null) { + keys = keysToMirror.iterator(); + } else { + IQueryResult<IArtifactKey> result = source.query(ArtifactKeyQuery.ALL_KEYS, null); + keys = result.iterator(); + } + while (keys.hasNext()) { + IArtifactKey artifactKey = keys.next(); + IArtifactDescriptor[] srcDescriptors = source.getArtifactDescriptors(artifactKey); + IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(artifactKey); + + Arrays.sort(srcDescriptors, new ArtifactDescriptorComparator()); + Arrays.sort(destDescriptors, new ArtifactDescriptorComparator()); + + int src = 0; + int dest = 0; + while (src < srcDescriptors.length && dest < destDescriptors.length) { + if (!destDescriptors[dest].equals(srcDescriptors[src])) { + if (destDescriptors[dest].toString().compareTo((srcDescriptors[src].toString())) > 0) { + // Missing an artifact + if (verbose) + System.out.println(NLS.bind(Messages.Mirroring_missingDescriptor, srcDescriptors[src])); + status.add(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Mirroring_missingDescriptor, srcDescriptors[src++]))); + } else { + // Its okay if there are extra descriptors in the destination + dest++; + } + } else { + // check properties for differences + Map<String, String> destMap = destDescriptors[dest].getProperties(); + Map<String, String> srcProperties = null; + if (baseline != null) { + IArtifactDescriptor baselineDescriptor = getBaselineDescriptor(destDescriptors[dest]); + if (baselineDescriptor != null) + srcProperties = baselineDescriptor.getProperties(); + } + // Baseline not set, or could not find descriptor so we'll use the source descriptor + if (srcProperties == null) + srcProperties = srcDescriptors[src].getProperties(); + + // Cycle through properties of the originating descriptor & compare + for (String key : srcProperties.keySet()) { + if (!srcProperties.get(key).equals(destMap.get(key))) { + if (verbose) + System.out.println(NLS.bind(Messages.Mirroring_differentDescriptorProperty, new Object[] {destDescriptors[dest], key, srcProperties.get(key), destMap.get(key)})); + status.add(new Status(IStatus.WARNING, Activator.ID, NLS.bind(Messages.Mirroring_differentDescriptorProperty, new Object[] {destDescriptors[dest], key, srcProperties.get(key), destMap.get(key)}))); + } + } + src++; + dest++; + } + } + + // If there are still source descriptors they're missing from the destination repository + while (src < srcDescriptors.length) { + if (verbose) + System.out.println(NLS.bind(Messages.Mirroring_missingDescriptor, srcDescriptors[src])); + status.add(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Mirroring_missingDescriptor, srcDescriptors[src++]))); + } + } + + return status; + } + + // Simple comparator for ArtifactDescriptors + protected class ArtifactDescriptorComparator implements Comparator<IArtifactDescriptor> { + + public int compare(IArtifactDescriptor arg0, IArtifactDescriptor arg1) { + if (arg0 != null && arg1 != null) + return arg0.toString().compareTo(arg1.toString()); + else if (arg1 == null && arg0 == null) + return 0; + else if (arg1 == null) + return 1; + return -1; + } + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog.java new file mode 100644 index 000000000..0b488f73a --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.mirroring; + +import java.io.*; +import java.util.Date; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.artifact.repository.Messages; +import org.eclipse.equinox.internal.p2.persistence.XMLWriter; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; + +public class XMLMirrorLog implements IArtifactMirrorLog { + private static final String DEFAULT_FORMAT = "canonical"; //$NON-NLS-1$ + // Constants used in XML tags + private static final String LOG = "log"; //$NON-NLS-1$ + private static final String TIME_ATTRIBUTE = "time"; //$NON-NLS-1$ + private static final String DESCRIPTOR_ELEMENT = "descriptor"; //$NON-NLS-1$ + private static final String DESCRIPTOR_CLASSIFIER_ATTRIBUTE = "classifier"; //$NON-NLS-1$ + private static final String DESCRIPTOR_FORMAT_ATTRIBUTE = "format"; //$NON-NLS-1$ + private static final String DESCRIPTOR_ID_ATTRIBUTE = "id"; //$NON-NLS-1$ + private static final String DESCRIPTOR_VERSION_ATTRIBUTE = "version"; //$NON-NLS-1$ + private static final String STATUS_ELEMENT = "status"; //$NON-NLS-1$ + private static final String STATUS_SEVERITY_ATTRIBUTE = "severity"; //$NON-NLS-1$ + private static final String STATUS_MESSAGE_ATTRIBUTE = "message"; //$NON-NLS-1$ + + private int minStatus = IStatus.OK; + private XMLWriter writer; + private OutputStream outputStream; + private boolean consoleMessage = false; + + public XMLMirrorLog(String location, int minStatus, String root) { + this.minStatus = minStatus; + + try { + outputStream = new FileOutputStream(location); + writer = new XMLWriter(outputStream, null); + if (root != null) + writer.start(root.toLowerCase()); + else + writer.start(LOG); + writer.attribute(TIME_ATTRIBUTE, new Date()); + } catch (UnsupportedEncodingException e) { + exceptionOccurred(e); + } catch (FileNotFoundException e) { + exceptionOccurred(e); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#log(org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor, org.eclipse.core.runtime.IStatus) + */ + public void log(IArtifactDescriptor descriptor, IStatus status) { + if (status.getSeverity() < minStatus) + return; + // Start descriptor tag + if (writer != null) { + writer.start(DESCRIPTOR_ELEMENT); + writer.attribute(DESCRIPTOR_ID_ATTRIBUTE, descriptor.getArtifactKey().getId()); + writer.attribute(DESCRIPTOR_CLASSIFIER_ATTRIBUTE, descriptor.getArtifactKey().getClassifier()); + writer.attribute(DESCRIPTOR_VERSION_ATTRIBUTE, descriptor.getArtifactKey().getVersion()); + if (descriptor.getProperties().get(IArtifactDescriptor.FORMAT) != null) + writer.attribute(DESCRIPTOR_FORMAT_ATTRIBUTE, descriptor.getProperties().get(IArtifactDescriptor.FORMAT)); + else + writer.attribute(DESCRIPTOR_FORMAT_ATTRIBUTE, DEFAULT_FORMAT); + } else + // Creation of the XML writer failed, dump results to the console + System.out.println(descriptor); + + log(status); + + // Close descriptor tag + if (writer != null) + writer.end(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#log(org.eclipse.core.runtime.IStatus) + */ + public void log(IStatus status) { + if (status.getSeverity() < minStatus) + return; + + if (writer != null) { + // Start status tag + writer.start(STATUS_ELEMENT); + // Set severity attribute + switch (status.getSeverity()) { + case IStatus.OK : + writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "OK"); //$NON-NLS-1$ + break; + case IStatus.INFO : + writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "INFO"); //$NON-NLS-1$ + break; + case IStatus.WARNING : + writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "WARNING"); //$NON-NLS-1$ + break; + case IStatus.ERROR : + writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "ERROR"); //$NON-NLS-1$ + break; + case IStatus.CANCEL : + writer.attribute(STATUS_SEVERITY_ATTRIBUTE, "CANCEL"); //$NON-NLS-1$ + break; + default : + writer.attribute(STATUS_SEVERITY_ATTRIBUTE, status.getSeverity()); + } + // Set message attribute + writer.attribute(STATUS_MESSAGE_ATTRIBUTE, status.getMessage()); + } else + // Creation of the XML writer failed, dump results to the console + System.out.println(status); + + // Log children statuses + IStatus[] nestedStatus = status.getChildren(); + if (nestedStatus != null) + for (int i = 0; i < nestedStatus.length; i++) + log(nestedStatus[i]); + + // Close status tag + if (writer != null) + writer.end(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.equinox.internal.p2.artifact.mirror.IArtifactMirrorLog#close() + */ + public void close() { + try { + if (writer != null) { + // Close opening tag & flush results + writer.end(); + writer.flush(); + } + } finally { + if (outputStream != null) + try { + // Close output stream + outputStream.close(); + } catch (IOException e) { + exceptionOccurred(e); + } + } + } + + /* + * Show an error message if this the first time + */ + private void exceptionOccurred(Exception e) { + if (!consoleMessage) { + System.err.println(Messages.MirrorLog_Exception_Occurred); + e.printStackTrace(System.err); + System.err.println(Messages.MirrorLog_Console_Log); + consoleMessage = true; + } + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java index 0181e06d1..c1d1bb18c 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 IBM Corporation and others. + * Copyright (c) 2009, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,24 +15,29 @@ import java.util.*; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; +import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepositoryFactory; +import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; +import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepositoryFactory; import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.repository.*; +import org.eclipse.equinox.p2.core.*; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.*; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.osgi.util.NLS; +import org.osgi.framework.ServiceReference; public abstract class AbstractApplication { protected boolean removeAddedRepositories = true; - protected List sourceRepositories = new ArrayList(); //List of repository descriptors - protected List artifactReposToRemove = new ArrayList(); - protected List metadataReposToRemove = new ArrayList(); - protected List sourceIUs = new ArrayList(); - private List destinationRepos = new ArrayList(); + protected List<RepositoryDescriptor> sourceRepositories = new ArrayList<RepositoryDescriptor>(); //List of repository descriptors + protected List<URI> artifactReposToRemove = new ArrayList<URI>(); + protected List<URI> metadataReposToRemove = new ArrayList<URI>(); + protected List<IInstallableUnit> sourceIUs = new ArrayList<IInstallableUnit>(); + private List<RepositoryDescriptor> destinationRepos = new ArrayList<RepositoryDescriptor>(); protected IArtifactRepository destinationArtifactRepository = null; protected IMetadataRepository destinationMetadataRepository = null; @@ -40,18 +45,50 @@ public abstract class AbstractApplication { private CompositeMetadataRepository compositeMetadataRepository = null; private CompositeArtifactRepository compositeArtifactRepository = null; - public void setSourceIUs(List ius) { + protected IProvisioningAgent agent; + + public AbstractApplication() { + super(); + try { + setupAgent(); + } catch (ProvisionException e) { + LogHelper.log(e); + } + } + + private void setupAgent() throws ProvisionException { + //note if we ever wanted these applications to act on a different agent than + //the currently running system we would need to set it here + ServiceReference agentRef = Activator.getBundleContext().getServiceReference(IProvisioningAgent.SERVICE_NAME); + if (agentRef != null) { + agent = (IProvisioningAgent) Activator.getBundleContext().getService(agentRef); + if (agent != null) + return; + } + //there is no agent around so we need to create one + ServiceReference providerRef = Activator.getBundleContext().getServiceReference(IProvisioningAgentProvider.SERVICE_NAME); + if (providerRef == null) + throw new RuntimeException("No provisioning agent provider is available"); //$NON-NLS-1$ + IProvisioningAgentProvider provider = (IProvisioningAgentProvider) Activator.getBundleContext().getService(providerRef); + if (provider == null) + throw new RuntimeException("No provisioning agent provider is available"); //$NON-NLS-1$ + //obtain agent for currently running system + agent = provider.createAgent(null); + Activator.getBundleContext().ungetService(providerRef); + } + + public void setSourceIUs(List<IInstallableUnit> ius) { sourceIUs = ius; } - protected void finalizeRepositories() throws ProvisionException { + protected void finalizeRepositories() { if (removeAddedRepositories) { - IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); - for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();) - artifactRepositoryManager.removeRepository((URI) iter.next()); - IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); - for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();) - metadataRepositoryManager.removeRepository((URI) iter.next()); + IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager(); + for (URI uri : artifactReposToRemove) + artifactRepositoryManager.removeRepository(uri); + IMetadataRepositoryManager metadataRepositoryManager = getMetadataRepositoryManager(); + for (URI uri : metadataReposToRemove) + metadataRepositoryManager.removeRepository(uri); } metadataReposToRemove = null; artifactReposToRemove = null; @@ -61,13 +98,20 @@ public abstract class AbstractApplication { destinationMetadataRepository = null; } + protected IMetadataRepositoryManager getMetadataRepositoryManager() { + return (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); + } + + protected IArtifactRepositoryManager getArtifactRepositoryManager() { + return (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); + } + public void initializeRepos(IProgressMonitor progress) throws ProvisionException { - IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); - IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); + IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager(); + IMetadataRepositoryManager metadataRepositoryManager = getMetadataRepositoryManager(); URI curLocation = null; try { - for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) { - RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); + for (RepositoryDescriptor repo : sourceRepositories) { curLocation = repo.getRepoLocation(); if (repo.isBoth()) { addRepository(artifactRepositoryManager, curLocation, 0, progress); @@ -106,9 +150,9 @@ public abstract class AbstractApplication { RepositoryDescriptor artifactRepoDescriptor = null; RepositoryDescriptor metadataRepoDescriptor = null; - Iterator iter = destinationRepos.iterator(); + Iterator<RepositoryDescriptor> iter = destinationRepos.iterator(); while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) { - RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); + RepositoryDescriptor repo = iter.next(); if (repo.isArtifact() && artifactRepoDescriptor == null) artifactRepoDescriptor = repo; if (repo.isMetadata() && metadataRepoDescriptor == null) @@ -188,12 +232,12 @@ public abstract class AbstractApplication { } } - protected boolean initDestinationRepository(IRepository repository, RepositoryDescriptor descriptor) { + protected boolean initDestinationRepository(IRepository<?> repository, RepositoryDescriptor descriptor) { if (repository != null && repository.isModifiable()) { if (descriptor.getName() != null) repository.setName(descriptor.getName()); - if (repository instanceof ICompositeRepository && !descriptor.isAppend()) - ((ICompositeRepository) repository).removeAllChildren(); + if (repository instanceof ICompositeRepository<?> && !descriptor.isAppend()) + ((ICompositeRepository<?>) repository).removeAllChildren(); else if (repository instanceof IMetadataRepository && !descriptor.isAppend()) ((IMetadataRepository) repository).removeAll(); else if (repository instanceof IArtifactRepository && !descriptor.isAppend()) @@ -206,12 +250,13 @@ public abstract class AbstractApplication { public IMetadataRepository getCompositeMetadataRepository() { if (compositeMetadataRepository == null) { try { - compositeMetadataRepository = new CompositeMetadataRepository(new URI("memory:/composite"), "parent metadata repo", null);//$NON-NLS-1$ //$NON-NLS-2$ + CompositeMetadataRepositoryFactory factory = new CompositeMetadataRepositoryFactory(); + factory.setAgent(agent); + compositeMetadataRepository = (CompositeMetadataRepository) factory.create(new URI("memory:/composite"), "parent metadata repo", CompositeMetadataRepository.REPOSITORY_TYPE, null);//$NON-NLS-1$ //$NON-NLS-2$ } catch (URISyntaxException e) { //Can't happen } - for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) { - RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); + for (RepositoryDescriptor repo : sourceRepositories) { if (repo.isMetadata()) compositeMetadataRepository.addChild(repo.getRepoLocation()); } @@ -222,12 +267,13 @@ public abstract class AbstractApplication { public IArtifactRepository getCompositeArtifactRepository() { if (compositeArtifactRepository == null) { try { - compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent artifact repo", null);//$NON-NLS-1$ //$NON-NLS-2$ + CompositeArtifactRepositoryFactory factory = new CompositeArtifactRepositoryFactory(); + factory.setAgent(agent); + compositeArtifactRepository = (CompositeArtifactRepository) factory.create(new URI("memory:/composite"), "parent artifact repo", CompositeArtifactRepository.REPOSITORY_TYPE, null);//$NON-NLS-1$ //$NON-NLS-2$ } catch (URISyntaxException e) { //Can't happen } - for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) { - RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); + for (RepositoryDescriptor repo : sourceRepositories) { if (repo.isArtifact()) compositeArtifactRepository.addChild(repo.getRepoLocation()); } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java index 5c101ea89..b79dc8ce4 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java @@ -10,15 +10,16 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.net.URI; import java.net.URISyntaxException; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; +import org.eclipse.equinox.p2.engine.IProfileRegistry; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.osgi.util.NLS; import org.osgi.framework.*; import org.osgi.service.packageadmin.PackageAdmin; @@ -74,7 +75,7 @@ public class Activator implements BundleActivator { * Return the artifact repository manager. Throw an exception if it cannot be obtained. */ public static IArtifactRepositoryManager getArtifactRepositoryManager() throws ProvisionException { - IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(getBundleContext(), IArtifactRepositoryManager.class.getName()); + IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(getBundleContext(), IArtifactRepositoryManager.SERVICE_NAME); if (manager == null) throw new ProvisionException(Messages.no_artifactRepo_manager); return manager; @@ -84,7 +85,7 @@ public class Activator implements BundleActivator { * Return the profile registry. Throw an exception if it cannot be found. */ static IProfileRegistry getProfileRegistry() throws ProvisionException { - IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(getBundleContext(), IProfileRegistry.class.getName()); + IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(getBundleContext(), IProfileRegistry.SERVICE_NAME); if (registry == null) throw new ProvisionException(Messages.no_profile_registry); return registry; @@ -112,7 +113,7 @@ public class Activator implements BundleActivator { * Return the metadata repository manager. Throw an exception if it cannot be obtained. */ public static IMetadataRepositoryManager getMetadataRepositoryManager() throws ProvisionException { - IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(getBundleContext(), IMetadataRepositoryManager.class.getName()); + IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(getBundleContext(), IMetadataRepositoryManager.SERVICE_NAME); if (manager == null) throw new ProvisionException(Messages.no_metadataRepo_manager); return manager; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/ArtifactRepositoryValidator.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/ArtifactRepositoryValidator.java new file mode 100644 index 000000000..3748fc12f --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/ArtifactRepositoryValidator.java @@ -0,0 +1,85 @@ +package org.eclipse.equinox.p2.internal.repository.tools; + +import org.eclipse.equinox.p2.repository.tools.comparator.ArtifactComparatorFactory; +import org.eclipse.equinox.p2.repository.tools.comparator.IArtifactComparator; + +import java.util.Iterator; +import java.util.List; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.repository.artifact.*; + +public class ArtifactRepositoryValidator { + + private IArtifactComparator comparator; + + public ArtifactRepositoryValidator(String comparatorId) throws ProvisionException { + comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorId); + if (comparatorId == null) + throw new ProvisionException(Messages.invalidComparatorId); + + } + + public IStatus validateRepository(IArtifactRepository repository) { + if (repository instanceof CompositeArtifactRepository) + return validateComposite((CompositeArtifactRepository) repository); + + IQueryResult<IArtifactKey> queryResult = repository.query(ArtifactKeyQuery.ALL_KEYS, new NullProgressMonitor()); + for (Iterator<IArtifactKey> iterator = queryResult.iterator(); iterator.hasNext();) { + IArtifactDescriptor[] descriptors = repository.getArtifactDescriptors(iterator.next()); + for (int i = 0; i < descriptors.length - 2; i++) { + IStatus compareResult = comparator.compare(repository, descriptors[i], repository, descriptors[i + 1]); + if (!compareResult.isOK()) { + return compareResult; + } + } + } + return Status.OK_STATUS; + } + + public IStatus validateComposite(CompositeArtifactRepository repository) { + List<IArtifactRepository> repos = repository.getLoadedChildren(); + IQueryResult<IArtifactKey> queryResult = repository.query(ArtifactKeyQuery.ALL_KEYS, new NullProgressMonitor()); + for (Iterator<IArtifactKey> iterator = queryResult.iterator(); iterator.hasNext();) { + IArtifactKey key = iterator.next(); + IArtifactRepository firstRepo = null; + for (IArtifactRepository child : repos) { + if (child.contains(key)) { + if (firstRepo == null) { + firstRepo = child; + continue; + } + + IArtifactDescriptor[] d1 = firstRepo.getArtifactDescriptors(key); + IArtifactDescriptor[] d2 = child.getArtifactDescriptors(key); + //If we assume each repo is internally consistant, we only need to compare one descriptor from each repo + IStatus compareResult = comparator.compare(firstRepo, d1[0], child, d2[0]); + if (!compareResult.isOK()) { + //LogHelper.log(compareResult); + return compareResult; + } + } + } + } + return Status.OK_STATUS; + } + + public IStatus validateComposite(CompositeArtifactRepository composite, IArtifactRepository repository) { + IQueryResult<IArtifactKey> queryResult = repository.query(ArtifactKeyQuery.ALL_KEYS, new NullProgressMonitor()); + for (Iterator<IArtifactKey> iterator = queryResult.iterator(); iterator.hasNext();) { + IArtifactKey key = iterator.next(); + if (composite.contains(key)) { + IArtifactDescriptor[] d1 = composite.getArtifactDescriptors(key); + IArtifactDescriptor[] d2 = repository.getArtifactDescriptors(key); + //If we assume each repo is internally consistant, we only need to compare one descriptor from each repo + IStatus compareResult = comparator.compare(composite, d1[0], repository, d2[0]); + if (!compareResult.isOK()) + return compareResult; + } + } + return Status.OK_STATUS; + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java index 11f73dee6..96de1e39d 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java @@ -11,22 +11,25 @@ package org.eclipse.equinox.p2.internal.repository.tools; import java.net.MalformedURLException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.repository.ICompositeRepository; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.ICompositeRepository; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.osgi.util.NLS; public class CompositeRepositoryApplication extends AbstractApplication { - private List childrenToAdd = new ArrayList(); - private List childrenToRemove = new ArrayList(); + private List<RepositoryDescriptor> childrenToAdd = new ArrayList<RepositoryDescriptor>(); + private List<RepositoryDescriptor> childrenToRemove = new ArrayList<RepositoryDescriptor>(); + private boolean removeAllChildren = false; private boolean failOnExists = false; private String comparatorID = null; @@ -34,30 +37,36 @@ public class CompositeRepositoryApplication extends AbstractApplication { try { initializeRepos(new NullProgressMonitor()); // load repository - ICompositeRepository metadataRepo = (ICompositeRepository) destinationMetadataRepository; + ICompositeRepository<IInstallableUnit> metadataRepo = (ICompositeRepository<IInstallableUnit>) destinationMetadataRepository; CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) destinationArtifactRepository; - // Remove children from the Composite Repositories - for (Iterator iterator = childrenToRemove.iterator(); iterator.hasNext();) { - RepositoryDescriptor child = (RepositoryDescriptor) iterator.next(); - if (child.isArtifact() && artifactRepo != null) - artifactRepo.removeChild(child.getOriginalRepoLocation()); - if (child.isMetadata() && metadataRepo != null) - metadataRepo.removeChild(child.getOriginalRepoLocation()); + if (removeAllChildren) { + if (artifactRepo != null) + artifactRepo.removeAllChildren(); + if (metadataRepo != null) + metadataRepo.removeAllChildren(); + } else { + // Remove children from the Composite Repositories + for (RepositoryDescriptor child : childrenToRemove) { + if (child.isArtifact() && artifactRepo != null) + artifactRepo.removeChild(child.getOriginalRepoLocation()); + if (child.isMetadata() && metadataRepo != null) + metadataRepo.removeChild(child.getOriginalRepoLocation()); + } } // Add children to the Composite Repositories - for (Iterator iterator = childrenToAdd.iterator(); iterator.hasNext();) { - RepositoryDescriptor child = (RepositoryDescriptor) iterator.next(); + for (RepositoryDescriptor child : childrenToAdd) { if (child.isArtifact() && artifactRepo != null) artifactRepo.addChild(child.getOriginalRepoLocation()); if (child.isMetadata() && metadataRepo != null) metadataRepo.addChild(child.getOriginalRepoLocation()); } - if (comparatorID != null) - if (!artifactRepo.validate(comparatorID)) - return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.CompositeRepositoryApplication_failedComparator, comparatorID)); + if (comparatorID != null) { + ArtifactRepositoryValidator validator = new ArtifactRepositoryValidator(comparatorID); + return validator.validateComposite(artifactRepo); + } return Status.OK_STATUS; } finally { finalizeRepositories(); @@ -72,6 +81,10 @@ public class CompositeRepositoryApplication extends AbstractApplication { childrenToRemove.add(child); } + public void setRemoveAll(boolean all) { + removeAllChildren = all; + } + public void setFailOnExists(boolean value) { failOnExists = value; } @@ -155,8 +168,8 @@ public class CompositeRepositoryApplication extends AbstractApplication { /* * Determine if the repository is valid for this operation */ - private boolean validRepositoryLocation(IRepository repository) throws ProvisionException { - if (repository instanceof ICompositeRepository) { + private boolean validRepositoryLocation(IRepository<?> repository) throws ProvisionException { + if (repository instanceof ICompositeRepository<?>) { // if we have an already existing repository at that location, then throw an error // if the user told us to if (failOnExists) @@ -171,7 +184,7 @@ public class CompositeRepositoryApplication extends AbstractApplication { /* * Initialize a new repository */ - private void initRepository(IRepository repository, RepositoryDescriptor desc) { + private void initRepository(IRepository<?> repository, RepositoryDescriptor desc) { RepositoryHelper.validDestinationRepository(repository); if (desc.isCompressed() && !repository.getProperties().containsKey(IRepository.PROP_COMPRESSED)) repository.setProperty(IRepository.PROP_COMPRESSED, String.valueOf(true)); diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java index 1f4b3c69c..37a7c5d12 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java @@ -18,9 +18,11 @@ public class Messages extends NLS { public static String exception_unableToRemoveRepo; public static String exception_notLocalFileRepo; public static String exception_noEngineService; + public static String exception_noPlannerService; public static String exception_needIUsOrNonEmptyRepo; public static String exception_needDestinationRepo; public static String exception_onlyOneComparator; + public static String exception_loadingRepository; public static String AbstractApplication_no_valid_destinations; @@ -40,11 +42,8 @@ public class Messages extends NLS { public static String MirrorApplication_artifactDestinationNoSource; public static String MirrorApplication_metadataDestinationNoSource; - public static String MirrorApplication_missingIU; - public static String MirrorApplication_missingSourceForIUs; public static String MirrorApplication_no_IUs; public static String MirrorApplication_set_source_repositories; - public static String MirrorApplication_validateAndMirrorProblems; public static String ProcessRepo_location_not_url; public static String ProcessRepo_must_be_local; @@ -58,6 +57,19 @@ public class Messages extends NLS { public static String skippingInvalidFilter; + public static String message_mirroringStatus; + public static String Mirroring_compareAndDownload; + public static String mirror_alreadyExists; + public static String Mirroring_noMatchingDescriptor; + public static String Mirroring_ValidationError; + public static String Mirroring_missingDescriptor; + public static String Mirroring_differentDescriptorProperty; + + public static String invalidComparatorId; + public static String info_noMD5Infomation; + public static String info_noMD5InRepository; + public static String warning_differentMD5; + static { // initialize resource bundles NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java index e73283eed..574abd9bc 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java @@ -10,30 +10,33 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector; - -import org.eclipse.equinox.internal.provisional.p2.metadata.query.IQueryable; +import org.eclipse.equinox.p2.metadata.VersionRange; import java.io.File; import java.net.URI; -import java.util.ArrayList; -import java.util.Iterator; +import java.net.URISyntaxException; +import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; -import org.eclipse.equinox.internal.p2.artifact.mirror.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.LatestIUVersionQuery; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; - -public class MirrorApplication extends AbstractApplication { +import org.eclipse.equinox.internal.p2.metadata.query.LatestIUVersionQuery; +import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.internal.repository.mirroring.*; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.query.IQueryable; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.osgi.util.NLS; + +public class MirrorApplication extends AbstractApplication implements IApplication, IExecutableExtension { private static final String LOG_ROOT = "p2.mirror"; //$NON-NLS-1$ + private static final String MIRROR_MODE = "metadataOrArtifacts"; //$NON-NLS-1$ protected SlicingOptions slicingOptions = new SlicingOptions(); @@ -44,17 +47,132 @@ public class MirrorApplication extends AbstractApplication { private boolean raw = true; private boolean verbose = false; private boolean validate = false; + private String metadataOrArtifacts = null; + private String[] rootIUs = null; private File mirrorLogFile; // file to log mirror output to (optional) private File comparatorLogFile; // file to comparator output to (optional) private IArtifactMirrorLog mirrorLog; private IArtifactMirrorLog comparatorLog; + /** + * Convert a list of tokens into an array. The list separator has to be + * specified. + */ + public static String[] getArrayArgsFromString(String list, String separator) { + if (list == null || list.trim().equals("")) //$NON-NLS-1$ + return new String[0]; + List<String> result = new ArrayList<String>(); + for (StringTokenizer tokens = new StringTokenizer(list, separator); tokens.hasMoreTokens();) { + String token = tokens.nextToken().trim(); + if (!token.equals("")) { //$NON-NLS-1$ + if ((token.indexOf('[') >= 0 || token.indexOf('(') >= 0) && tokens.hasMoreTokens()) + result.add(token + separator + tokens.nextToken()); + else + result.add(token); + } + } + return result.toArray(new String[result.size()]); + } + public Object start(IApplicationContext context) throws Exception { + Map<?, ?> args = context.getArguments(); + initializeFromArguments((String[]) args.get(IApplicationContext.APPLICATION_ARGS)); run(null); return IApplication.EXIT_OK; } + public void stop() { + // TODO Auto-generated method stub + + } + + /* + * The old "org.eclipse.equinox.p2.artifact.repository.mirrorApplication" application only does artifacts + * Similary, "org.eclipse.equinox.p2.metadata.repository.mirrorApplication" only does metadata + */ + public void setInitializationData(IConfigurationElement config, String propertyName, Object data) { + if (data instanceof Map<?, ?> && ((Map<?, ?>) data).containsKey(MIRROR_MODE)) { + metadataOrArtifacts = (String) ((Map<?, ?>) data).get(MIRROR_MODE); + } + } + + public void initializeFromArguments(String[] args) throws Exception { + if (args == null) + return; + + File comparatorLogLocation = null; + File mirrorLogLocation = null; + + RepositoryDescriptor destination = new RepositoryDescriptor(); + RepositoryDescriptor sourceRepo = new RepositoryDescriptor(); + if (metadataOrArtifacts != null) { + destination.setKind(metadataOrArtifacts); + sourceRepo.setKind(metadataOrArtifacts); + } + + addDestination(destination); + addSource(sourceRepo); + + for (int i = 0; i < args.length; i++) { + // check for args without parameters (i.e., a flag arg) + if (args[i].equalsIgnoreCase("-raw")) //$NON-NLS-1$ + raw = true; + else if (args[i].equalsIgnoreCase("-ignoreErrors")) //$NON-NLS-1$ + failOnError = false; + else if (args[i].equalsIgnoreCase("-verbose")) //$NON-NLS-1$ + verbose = true; + else if (args[i].equalsIgnoreCase("-compare")) //$NON-NLS-1$ + compare = true; + else if (args[i].equalsIgnoreCase("-validate")) //$NON-NLS-1$ + validate = true; + + // check for args with parameters. If we are at the last argument or + // if the next one has a '-' as the first character, then we can't have + // an arg with a param so continue. + if (i == args.length - 1 || args[i + 1].startsWith("-")) //$NON-NLS-1$ + continue; + + String arg = args[++i]; + + if (args[i - 1].equalsIgnoreCase("-comparator")) //$NON-NLS-1$ + comparatorID = arg; + else if (args[i - 1].equalsIgnoreCase("-comparatorLog")) //$NON-NLS-1$ + comparatorLogLocation = new File(arg); + else if (args[i - 1].equalsIgnoreCase("-destinationName")) //$NON-NLS-1$ + destination.setName(arg); + else if (args[i - 1].equalsIgnoreCase("-writeMode")) { //$NON-NLS-1$ + if (args[i].equalsIgnoreCase("clean")) //$NON-NLS-1$ + destination.setAppend(false); + } else if (args[i - 1].equalsIgnoreCase("-log")) { //$NON-NLS-1$ + mirrorLogLocation = new File(arg); + } else if (args[i - 1].equalsIgnoreCase("-roots")) { //$NON-NLS-1$ + rootIUs = getArrayArgsFromString(arg, ","); //$NON-NLS-1$ + } else { + try { + if (args[i - 1].equalsIgnoreCase("-source")) { //$NON-NLS-1$ + URI uri = RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg)); + sourceRepo.setLocation(uri); + destination.setFormat(uri); + } else if (args[i - 1].equalsIgnoreCase("-destination")) //$NON-NLS-1$ + destination.setLocation(RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg))); + else if (args[i - 1].equalsIgnoreCase("-compareAgainst")) { //$NON-NLS-1$ + baseline = RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg)); + compare = true; + } + } catch (URISyntaxException e) { + throw new IllegalArgumentException(NLS.bind(Messages.ProcessRepo_location_not_url, arg)); + } + } + } + + // Create logs + if (mirrorLogLocation != null) + mirrorLog = getLog(mirrorLogLocation, "p2.artifact.mirror"); //$NON-NLS-1$ + if (comparatorLogLocation != null && comparatorID != null) + comparatorLog = getLog(comparatorLogLocation, comparatorID); + } + public IStatus run(IProgressMonitor monitor) throws ProvisionException { IStatus mirrorStatus = Status.OK_STATUS; try { @@ -62,7 +180,7 @@ public class MirrorApplication extends AbstractApplication { initializeLogs(); validate(); initializeIUs(); - IQueryable slice = slice(new NullProgressMonitor()); + IQueryable<IInstallableUnit> slice = slice(new NullProgressMonitor()); if (destinationArtifactRepository != null) { mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor()); if (mirrorStatus.getSeverity() == IStatus.ERROR) @@ -79,19 +197,16 @@ public class MirrorApplication extends AbstractApplication { return mirrorStatus; } - private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) throws ProvisionException { + private IStatus mirrorArtifacts(IQueryable<IInstallableUnit> slice, IProgressMonitor monitor) throws ProvisionException { // Obtain ArtifactKeys from IUs - Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor); - ArrayList keys = new ArrayList(ius.size()); - for (Iterator iterator = ius.iterator(); iterator.hasNext();) { - IInstallableUnit iu = (IInstallableUnit) iterator.next(); - IArtifactKey[] iuKeys = iu.getArtifacts(); - for (int i = 0; i < iuKeys.length; i++) { - keys.add(iuKeys[i]); - } + IQueryResult<IInstallableUnit> ius = slice.query(InstallableUnitQuery.ANY, monitor); + ArrayList<IArtifactKey> keys = new ArrayList<IArtifactKey>(); + for (Iterator<IInstallableUnit> iterator = ius.iterator(); iterator.hasNext();) { + IInstallableUnit iu = iterator.next(); + keys.addAll(iu.getArtifacts()); } - Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw); + Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw); mirror.setCompare(compare); mirror.setComparatorId(comparatorID); mirror.setBaseline(initializeBaseline()); @@ -99,7 +214,7 @@ public class MirrorApplication extends AbstractApplication { // If IUs have been specified then only they should be mirrored, otherwise mirror everything. if (keys.size() > 0) - mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()])); + mirror.setArtifactKeys(keys.toArray(new IArtifactKey[keys.size()])); if (comparatorLog != null) mirror.setComparatorLog(comparatorLog); @@ -116,12 +231,12 @@ public class MirrorApplication extends AbstractApplication { private IArtifactRepository initializeBaseline() throws ProvisionException { if (baseline == null) return null; - return addRepository(Activator.getArtifactRepositoryManager(), baseline, 0, null); + return addRepository(getArtifactRepositoryManager(), baseline, 0, null); } - private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) { - Collector allIUs = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor); - destinationMetadataRepository.addInstallableUnits((IInstallableUnit[]) allIUs.toArray(IInstallableUnit.class)); + private void mirrorMetadata(IQueryable<IInstallableUnit> slice, IProgressMonitor monitor) { + IQueryResult<IInstallableUnit> allIUs = slice.query(InstallableUnitQuery.ANY, monitor); + destinationMetadataRepository.addInstallableUnits(allIUs.toArray(IInstallableUnit.class)); } /* @@ -143,17 +258,24 @@ public class MirrorApplication extends AbstractApplication { * If no IUs have been specified we want to mirror them all */ private void initializeIUs() throws ProvisionException { - if (sourceIUs == null || sourceIUs.isEmpty()) { - sourceIUs = new ArrayList(); - IMetadataRepository metadataRepo = getCompositeMetadataRepository(); - Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, new Collector(), null); - - for (Iterator iter = collector.iterator(); iter.hasNext();) { - IInstallableUnit iu = (IInstallableUnit) iter.next(); - sourceIUs.add(iu); + IMetadataRepository metadataRepo = getCompositeMetadataRepository(); + + if (rootIUs != null) { + sourceIUs = new ArrayList<IInstallableUnit>(); + for (int i = 0; i < rootIUs.length; i++) { + String[] segments = getArrayArgsFromString(rootIUs[i], "/"); //$NON-NLS-1$ + VersionRange range = segments.length > 1 ? new VersionRange(segments[i]) : null; + Iterator<IInstallableUnit> queryResult = metadataRepo.query(new InstallableUnitQuery(segments[i], range), null).iterator(); + while (queryResult.hasNext()) + sourceIUs.add(queryResult.next()); } - - if (collector.size() == 0 && destinationMetadataRepository != null) + } else if (sourceIUs == null || sourceIUs.isEmpty()) { + sourceIUs = new ArrayList<IInstallableUnit>(); + Iterator<IInstallableUnit> queryResult = metadataRepo.query(InstallableUnitQuery.ANY, null).iterator(); + while (queryResult.hasNext()) + sourceIUs.add(queryResult.next()); + /* old metadata mirroring app did not throw an exception here */ + if (sourceIUs.size() == 0 && destinationMetadataRepository != null && metadataOrArtifacts == null) throw new ProvisionException(Messages.MirrorApplication_no_IUs); } } @@ -188,16 +310,15 @@ public class MirrorApplication extends AbstractApplication { return new FileMirrorLog(absolutePath, 0, root); } - private IQueryable slice(IProgressMonitor monitor) throws ProvisionException { + private IQueryable<IInstallableUnit> slice(IProgressMonitor monitor) throws ProvisionException { if (slicingOptions == null) slicingOptions = new SlicingOptions(); PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), slicingOptions.getFilter(), slicingOptions.includeOptionalDependencies(), slicingOptions.isEverythingGreedy(), slicingOptions.forceFilterTo(), slicingOptions.considerStrictDependencyOnly(), slicingOptions.followOnlyFilteredRequirements()); - IQueryable slice = slicer.slice((IInstallableUnit[]) sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]), monitor); + IQueryable<IInstallableUnit> slice = slicer.slice(sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]), monitor); if (slice != null && slicingOptions.latestVersionOnly()) { - Collector collector = new Collector(); - collector = slice.query(new LatestIUVersionQuery(), collector, monitor); - slice = collector; + IQueryResult<IInstallableUnit> queryResult = slice.query(new LatestIUVersionQuery<IInstallableUnit>(), monitor); + slice = queryResult; } if (slicer.getStatus().getSeverity() != IStatus.OK && mirrorLog != null) { mirrorLog.log(slicer.getStatus()); diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java index adb7535d3..adaa79af6 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java @@ -17,31 +17,32 @@ import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.*; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor; import org.eclipse.osgi.util.NLS; -public class RecreateRepositoryApplication { +public class RecreateRepositoryApplication extends AbstractApplication { static final private String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$ private RepositoryDescriptor descriptor; private String repoName = null; boolean removeArtifactRepo = true; - private Map repoProperties = null; - private Map repoMap = null; - - public IStatus run(IProgressMonitor monitor) throws ProvisionException, IOException { + private Map<String, String> repoProperties = null; + private Map<IArtifactKey, IArtifactDescriptor[]> repoMap = null; + public IStatus run(IProgressMonitor monitor) throws ProvisionException { try { IArtifactRepository repository = initialize(monitor); removeRepository(repository, monitor); recreateRepository(monitor); } finally { if (removeArtifactRepo) { - IArtifactRepositoryManager repositoryManager = Activator.getArtifactRepositoryManager(); + IArtifactRepositoryManager repositoryManager = getArtifactRepositoryManager(); repositoryManager.removeRepository(descriptor.getRepoLocation()); } } @@ -54,7 +55,7 @@ public class RecreateRepositoryApplication { } private IArtifactRepository initialize(IProgressMonitor monitor) throws ProvisionException { - IArtifactRepositoryManager repositoryManager = Activator.getArtifactRepositoryManager(); + IArtifactRepositoryManager repositoryManager = getArtifactRepositoryManager(); removeArtifactRepo = !repositoryManager.contains(descriptor.getRepoLocation()); IArtifactRepository repository = repositoryManager.loadRepository(descriptor.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, monitor); @@ -67,46 +68,49 @@ public class RecreateRepositoryApplication { repoName = repository.getName(); repoProperties = repository.getProperties(); - repoMap = new HashMap(); - IArtifactKey[] keys = repository.getArtifactKeys(); - for (int i = 0; i < keys.length; i++) { - IArtifactDescriptor[] descriptors = repository.getArtifactDescriptors(keys[i]); - repoMap.put(keys[i], descriptors); + repoMap = new HashMap<IArtifactKey, IArtifactDescriptor[]>(); + IQueryResult<IArtifactKey> keys = repository.query(ArtifactKeyQuery.ALL_KEYS, null); + for (Iterator<IArtifactKey> iterator = keys.iterator(); iterator.hasNext();) { + IArtifactKey key = iterator.next(); + IArtifactDescriptor[] descriptors = repository.getArtifactDescriptors(key); + repoMap.put(key, descriptors); } return repository; } - private void removeRepository(IArtifactRepository repository, IProgressMonitor monitor) throws ProvisionException, IOException { - IArtifactRepositoryManager manager = Activator.getArtifactRepositoryManager(); + private void removeRepository(IArtifactRepository repository, IProgressMonitor monitor) throws ProvisionException { + IArtifactRepositoryManager manager = getArtifactRepositoryManager(); manager.removeRepository(repository.getLocation()); - boolean compressed = Boolean.valueOf((String) repoProperties.get(IRepository.PROP_COMPRESSED)).booleanValue(); - URI realLocation = SimpleArtifactRepository.getActualLocation(repository.getLocation(), compressed); - File realFile = URIUtil.toFile(realLocation); - - if (!realFile.exists() || !realFile.delete()) - throw new ProvisionException(NLS.bind(Messages.exception_unableToRemoveRepo, realFile.toString())); + boolean compressed = Boolean.valueOf(repoProperties.get(IRepository.PROP_COMPRESSED)).booleanValue(); + try { + URI realLocation = SimpleArtifactRepository.getActualLocation(repository.getLocation(), compressed); + File realFile = URIUtil.toFile(realLocation); + if (!realFile.exists() || !realFile.delete()) + throw new ProvisionException(NLS.bind(Messages.exception_unableToRemoveRepo, realFile.toString())); + } catch (IOException e) { + throw new ProvisionException(NLS.bind(Messages.exception_unableToRemoveRepo, repository.getLocation().toString())); + } } private void recreateRepository(IProgressMonitor monitor) throws ProvisionException { - IArtifactRepositoryManager manager = Activator.getArtifactRepositoryManager(); + IArtifactRepositoryManager manager = getArtifactRepositoryManager(); //add pack200 mappings, the existing repoProperties is not modifiable - Map newProperties = new HashMap(repoProperties); + Map<String, String> newProperties = new HashMap<String, String>(repoProperties); newProperties.put(PUBLISH_PACK_FILES_AS_SIBLINGS, "true"); //$NON-NLS-1$ IArtifactRepository repository = manager.createRepository(descriptor.getRepoLocation(), repoName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, newProperties); if (!(repository instanceof IFileArtifactRepository)) throw new ProvisionException(NLS.bind(Messages.exception_notLocalFileRepo, repository.getLocation())); IFileArtifactRepository simple = (IFileArtifactRepository) repository; - for (Iterator iterator = repoMap.keySet().iterator(); iterator.hasNext();) { - IArtifactKey key = (IArtifactKey) iterator.next(); - IArtifactDescriptor[] descriptors = (IArtifactDescriptor[]) repoMap.get(key); + for (IArtifactKey key : repoMap.keySet()) { + IArtifactDescriptor[] descriptors = repoMap.get(key); String unpackedSize = null; File packFile = null; - Set files = new HashSet(); + Set<File> files = new HashSet<File>(); for (int i = 0; i < descriptors.length; i++) { File artifactFile = simple.getArtifactFile(descriptors[i]); files.add(artifactFile); @@ -137,15 +141,14 @@ public class RecreateRepositoryApplication { } private ArtifactDescriptor createPack200ArtifactDescriptor(IArtifactKey key, File packFile, String installSize) { - final String PACKED_FORMAT = "packed"; //$NON-NLS-1$ if (packFile != null && packFile.exists()) { ArtifactDescriptor result = new ArtifactDescriptor(key); result.setProperty(IArtifactDescriptor.ARTIFACT_SIZE, installSize); result.setProperty(IArtifactDescriptor.DOWNLOAD_SIZE, Long.toString(packFile.length())); - ProcessingStepDescriptor[] steps = new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true)}; //$NON-NLS-1$ + IProcessingStepDescriptor[] steps = new IProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true)}; //$NON-NLS-1$ result.setProcessingSteps(steps); - result.setProperty(IArtifactDescriptor.FORMAT, PACKED_FORMAT); + result.setProperty(IArtifactDescriptor.FORMAT, IArtifactDescriptor.FORMAT_PACKED); return result; } return null; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java index 07815f15f..067dc367b 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java @@ -16,17 +16,21 @@ import org.eclipse.core.runtime.*; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.p2.engine.DownloadManager; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.engine.phases.Collect; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; +import org.eclipse.equinox.internal.p2.engine.*; +import org.eclipse.equinox.internal.p2.engine.phases.Collect; +import org.eclipse.equinox.internal.provisional.p2.director.IPlanner; +import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; /** * The transformer takes an existing p2 repository (local or remote), iterates over @@ -42,31 +46,26 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { private static final String PARM_OPERAND = "operand"; //$NON-NLS-1$ protected class CollectNativesAction extends ProvisioningAction { - public IStatus execute(Map parameters) { + public IStatus execute(Map<String, Object> parameters) { InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(PARM_OPERAND); IInstallableUnit installableUnit = operand.second(); - IArtifactRepositoryManager manager = null; - try { - manager = Activator.getArtifactRepositoryManager(); - } catch (ProvisionException e) { - return e.getStatus(); - } - - IArtifactKey[] toDownload = installableUnit.getArtifacts(); + IArtifactRepositoryManager manager = getArtifactRepositoryManager(); + Collection<IArtifactKey> toDownload = installableUnit.getArtifacts(); if (toDownload == null) return Status.OK_STATUS; - List artifactRequests = (List) parameters.get(NATIVE_ARTIFACTS); + @SuppressWarnings("unchecked") + List<IArtifactRequest> artifactRequests = (List<IArtifactRequest>) parameters.get(NATIVE_ARTIFACTS); - for (int i = 0; i < toDownload.length; i++) { - IArtifactRequest request = manager.createMirrorRequest(toDownload[i], destinationArtifactRepository, null, null); + for (IArtifactKey keyToDownload : toDownload) { + IArtifactRequest request = manager.createMirrorRequest(keyToDownload, destinationArtifactRepository, null, null); artifactRequests.add(request); } return Status.OK_STATUS; } - public IStatus undo(Map parameters) { + public IStatus undo(Map<String, Object> parameters) { // nothing to do for now return Status.OK_STATUS; } @@ -77,26 +76,28 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { super(NATIVE_ARTIFACTS, weight); } - protected ProvisioningAction[] getActions(InstallableUnitOperand operand) { + protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) { IInstallableUnit unit = operand.second(); if (unit.getTouchpointType().getId().equals(NATIVE_TYPE)) { - return new ProvisioningAction[] {new CollectNativesAction()}; + return Collections.<ProvisioningAction> singletonList(new CollectNativesAction()); } return null; } - protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { + protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { parameters.put(NATIVE_ARTIFACTS, new ArrayList()); return null; } - protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) { - List artifactRequests = (List) parameters.get(NATIVE_ARTIFACTS); + protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) { + @SuppressWarnings("unchecked") + List<IArtifactRequest> artifactRequests = (List<IArtifactRequest>) parameters.get(NATIVE_ARTIFACTS); ProvisioningContext context = (ProvisioningContext) parameters.get(PARM_CONTEXT); - - DownloadManager dm = new DownloadManager(context); - for (Iterator it = artifactRequests.iterator(); it.hasNext();) { - dm.add((IArtifactRequest) it.next()); + IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT); + IArtifactRepositoryManager repositoryManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); + DownloadManager dm = new DownloadManager(context, repositoryManager); + for (IArtifactRequest request : artifactRequests) { + dm.add(request); } return dm.start(monitor); } @@ -104,7 +105,7 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { // the list of IUs that we actually transformed... could have come from the repo // or have been user-specified. - private Collection processedIUs = new ArrayList(); + private Collection<IInstallableUnit> processedIUs = new ArrayList<IInstallableUnit>(); /* * Perform the transformation. @@ -120,24 +121,25 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { // figure out which IUs we need to process collectIUs(progress.newChild(1)); - // create the operands from the list of IUs - InstallableUnitOperand[] operands = new InstallableUnitOperand[processedIUs.size()]; - int i = 0; - for (Iterator iter = processedIUs.iterator(); iter.hasNext();) - operands[i++] = new InstallableUnitOperand(null, (IInstallableUnit) iter.next()); - // call the engine with only the "collect" phase so all we do is download IProfile profile = createProfile(); try { + ProfileChangeRequest request = new ProfileChangeRequest(profile); + request.setAbsoluteMode(true); + request.addInstallableUnits(processedIUs.toArray(new IInstallableUnit[processedIUs.size()])); ProvisioningContext context = new ProvisioningContext(); IEngine engine = (IEngine) ServiceHelper.getService(Activator.getBundleContext(), IEngine.SERVICE_NAME); if (engine == null) throw new ProvisionException(Messages.exception_noEngineService); + IPlanner planner = (IPlanner) ServiceHelper.getService(Activator.getBundleContext(), IPlanner.SERVICE_NAME); + if (planner == null) + throw new ProvisionException(Messages.exception_noPlannerService); - IStatus result = engine.perform(profile, getPhaseSet(), operands, context, progress.newChild(1)); + IProvisioningPlan plan = planner.getProvisioningPlan(request, context, monitor); + IStatus result = engine.perform(plan, getPhaseSet(), progress.newChild(1)); PhaseSet nativeSet = getNativePhase(); if (nativeSet != null) - engine.perform(profile, nativeSet, operands, context, progress.newChild(1)); + engine.perform(plan, nativeSet, progress.newChild(1)); // publish the metadata to a destination - if requested publishMetadata(progress.newChild(1)); @@ -172,7 +174,9 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { if (!hasMetadataSources()) throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo); - processedIUs.addAll(getAllIUs(getCompositeMetadataRepository(), monitor).toCollection()); + Iterator<IInstallableUnit> itor = getAllIUs(getCompositeMetadataRepository(), monitor).iterator(); + while (itor.hasNext()) + processedIUs.add(itor.next()); if (processedIUs.isEmpty()) throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo); @@ -186,16 +190,16 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { // publishing the metadata is optional if (destinationMetadataRepository == null) return; - destinationMetadataRepository.addInstallableUnits((IInstallableUnit[]) processedIUs.toArray(new IInstallableUnit[processedIUs.size()])); + destinationMetadataRepository.addInstallableUnits(processedIUs.toArray(new IInstallableUnit[processedIUs.size()])); } /* * Return a collector over all the IUs contained in the given repository. */ - private Collector getAllIUs(IMetadataRepository repository, IProgressMonitor monitor) { + private IQueryResult<IInstallableUnit> getAllIUs(IMetadataRepository repository, IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, 2); try { - return repository.query(InstallableUnitQuery.ANY, new Collector(), progress.newChild(1)); + return repository.query(InstallableUnitQuery.ANY, progress.newChild(1)); } finally { progress.done(); } @@ -213,7 +217,7 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { * Create and return a new profile. */ private IProfile createProfile() throws ProvisionException { - Map properties = new Properties(); + Map<String, String> properties = new HashMap<String, String>(); properties.put(IProfile.PROP_CACHE, URIUtil.toFile(destinationArtifactRepository.getLocation()).getAbsolutePath()); properties.put(IProfile.PROP_INSTALL_FOLDER, URIUtil.toFile(destinationArtifactRepository.getLocation()).getAbsolutePath()); IProfileRegistry registry = Activator.getProfileRegistry(); diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryAnalyzerApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryAnalyzerApplication.java new file mode 100644 index 000000000..8a8503cca --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryAnalyzerApplication.java @@ -0,0 +1,68 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools; + +import java.net.URI; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.app.IApplicationContext; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; +import org.eclipse.equinox.p2.repository.tools.analyzer.RepositoryAnalyzer; + +/** + * + */ +public class RepositoryAnalyzerApplication implements IApplication { + + /* (non-Javadoc) + * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext) + */ + public Object start(IApplicationContext context) throws Exception { + + long start = System.currentTimeMillis(); + URI uri = new URI("http://download.eclipse.org/releases/galileo"); + IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getBundleContext(), IMetadataRepositoryManager.class.getName()); + IMetadataRepository repository = manager.loadRepository(uri, new NullProgressMonitor()); + RepositoryAnalyzer repositoryAnalyzer = new RepositoryAnalyzer(new IMetadataRepository[] {repository}); + IStatus status = repositoryAnalyzer.analyze(new NullProgressMonitor()); + IStatus[] children = status.getChildren(); + long time = (System.currentTimeMillis()) - start; + if (status.isOK()) + System.out.println("Repository Analyzer Finished succesfuly in " + time + " ms."); + else + System.out.println("Repository Analyzer Finished in " + time + " ms with status with errors."); + for (int i = 0; i < children.length; i++) { + if (children[i].isOK()) + System.out.print("[OK] "); + else + System.out.print("[Error] "); + System.out.println(children[i].getMessage()); + if (children[i].isMultiStatus() && children[i].getChildren() != null && children[i].getChildren().length > 0) { + IStatus[] subChildren = children[i].getChildren(); + for (int j = 0; j < subChildren.length; j++) { + System.out.println(" " + subChildren[j].getMessage()); + } + } + } + return IApplication.EXIT_OK; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.app.IApplication#stop() + */ + public void stop() { + // TODO Auto-generated method stub + + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java index 478f7fe10..f8c2ae76d 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java @@ -12,7 +12,7 @@ package org.eclipse.equinox.p2.internal.repository.tools; import java.net.URI; import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepository; import org.eclipse.osgi.util.NLS; public class RepositoryDescriptor { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/SlicingOptions.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/SlicingOptions.java index 6531d3696..639279ba6 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/SlicingOptions.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/SlicingOptions.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.p2.internal.repository.tools; import java.util.Dictionary; -import java.util.Properties; +import java.util.Hashtable; public class SlicingOptions { private boolean includeOptionalDependencies = true; @@ -20,7 +20,7 @@ public class SlicingOptions { private boolean considerStrictDependencyOnly = false; private boolean followOnlyFilteredRequirements = false; private boolean latestVersion = false; - private Dictionary filter = null; + private Dictionary<String, Object> filter = null; public boolean includeOptionalDependencies() { return includeOptionalDependencies; @@ -54,13 +54,13 @@ public class SlicingOptions { this.considerStrictDependencyOnly = strict; } - public Dictionary getFilter() { + public Dictionary<String, Object> getFilter() { if (filter == null) - filter = new Properties(); + filter = new Hashtable<String, Object>(); return filter; } - public void setFilter(Dictionary filter) { + public void setFilter(Dictionary<String, Object> filter) { this.filter = filter; } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/CopyrightAnalyzer.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/CopyrightAnalyzer.java new file mode 100644 index 000000000..ea1c42bcc --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/CopyrightAnalyzer.java @@ -0,0 +1,43 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.analyzer; + +import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.tools.analyzer.IUAnalyzer; + +/** + * This service checks that all Group IUs have a copyright. + */ +public class CopyrightAnalyzer extends IUAnalyzer { + + public void analyzeIU(IInstallableUnit iu) { + if (Boolean.valueOf(iu.getProperty(InstallableUnitDescription.PROP_TYPE_GROUP)).booleanValue()) { + if (iu.getCopyright() == null || iu.getCopyright().getBody().length() == 0) { + // If there is no copyright at all, this is an error + error(iu, "[ERROR] " + iu.getId() + " has no copyright"); + return; + } + if (iu.getCopyright() != null && iu.getCopyright().getBody().startsWith("%")) { + // If there is a copyright, but it starts with %, then check the default + // language for a copyright + String copyrightProperty = iu.getCopyright().getBody().substring(1); + if (iu.getProperty("df_LT." + copyrightProperty) == null) + error(iu, "[ERROR] " + iu.getId() + " has no copyright"); + } + } + } + + public void preAnalysis(IMetadataRepository repository) { + // do nothing + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/HostCheckAnalyzer.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/HostCheckAnalyzer.java new file mode 100644 index 000000000..ed9125b23 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/HostCheckAnalyzer.java @@ -0,0 +1,54 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.analyzer; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.equinox.internal.p2.metadata.RequiredCapability; +import org.eclipse.equinox.p2.metadata.*; +import org.eclipse.equinox.p2.metadata.expression.IMatchExpression; +import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.tools.analyzer.IUAnalyzer; + +/** + * This service checks that for each fragment the host can be resolved. + * Currently this service only checks requirements with the namespace "osgi.bundle" + */ +public class HostCheckAnalyzer extends IUAnalyzer { + + private IMetadataRepository repository; + + public void analyzeIU(IInstallableUnit iu) { + if (iu instanceof IInstallableUnitFragment) { + IInstallableUnitFragment fragment = (IInstallableUnitFragment) iu; + IRequirement[] hosts = fragment.getHost(); + for (int i = 0; i < hosts.length; i++) { + IMatchExpression<IInstallableUnit> hostMatch = hosts[i].getMatches(); + String namespace = RequiredCapability.extractNamespace(hostMatch); + if ("osgi.bundle".equals(namespace)) { + String name = RequiredCapability.extractName(hostMatch); + VersionRange range = RequiredCapability.extractRange(hostMatch); + IQueryResult<IInstallableUnit> results = repository.query(new InstallableUnitQuery(name, range), new NullProgressMonitor()); + if (results.isEmpty()) { + error(iu, "IU Fragment: " + iu.getId() + " cannot find host" + name + " : " + range); + return; + } + } + } + } + + } + + public void preAnalysis(IMetadataRepository repository) { + this.repository = repository; + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/IUCounting.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/IUCounting.java new file mode 100644 index 000000000..4f1589c48 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/IUCounting.java @@ -0,0 +1,57 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.analyzer; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.tools.analyzer.IIUAnalyzer; + +/** + * This service just counts the total number of IUs + */ +public class IUCounting implements IIUAnalyzer { + + int totalIUs = 0; + int totalGroups = 0; + int totalFragments = 0; + int totalCategories = 0; + + private boolean hasProperty(IInstallableUnit iu, String property) { + return Boolean.valueOf(iu.getProperty(property)).booleanValue(); + } + + public void analyzeIU(IInstallableUnit iu) { + totalIUs++; + if (hasProperty(iu, InstallableUnitDescription.PROP_TYPE_FRAGMENT)) + totalFragments++; + if (hasProperty(iu, InstallableUnitDescription.PROP_TYPE_GROUP)) + totalGroups++; + if (hasProperty(iu, InstallableUnitDescription.PROP_TYPE_CATEGORY)) + totalCategories++; + } + + public IStatus postAnalysis() { + System.out.println("Total IUs: " + totalIUs); + System.out.println(" Total Groups: " + totalGroups); + System.out.println(" Total Fragments: " + totalFragments); + System.out.println(" Total Categories: " + totalCategories); + return null; + } + + public void preAnalysis(IMetadataRepository repo) { + totalIUs = 0; + totalGroups = 0; + totalFragments = 0; + totalCategories = 0; + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/LicenseAnalyzer.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/LicenseAnalyzer.java new file mode 100644 index 000000000..452e12427 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/LicenseAnalyzer.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2009 EclipseSource and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * EclipseSource - initial API and implementation + ******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.analyzer; + +import org.eclipse.equinox.p2.metadata.ILicense; + +import java.util.Collection; +import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.tools.analyzer.IUAnalyzer; + +/** + * This service checks that each IU has a license. + */ +public class LicenseAnalyzer extends IUAnalyzer { + + public void analyzeIU(IInstallableUnit iu) { + if (Boolean.valueOf(iu.getProperty(InstallableUnitDescription.PROP_TYPE_GROUP)).booleanValue()) { + Collection<ILicense> licenses = iu.getLicenses(); + if (iu.getLicenses() == null || licenses.size() == 0) { + // If there is no license then this is an error + error(iu, "[ERROR] " + iu.getId() + " has no license"); + return; + } else if (licenses.iterator().next().getBody().length() == 0) { + error(iu, "[ERROR] " + iu.getId() + " has no license"); + return; + } + for (ILicense license : licenses) { + if (license.getBody().startsWith("%")) { + String licenseProperty = license.getBody().substring(1); + if (iu.getProperty("df_LT." + licenseProperty) == null) { + error(iu, "[ERROR] " + iu.getId() + " has no license"); + } + } + } + } + } + + public void preAnalysis(IMetadataRepository repository) { + // Do nothing + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/UniqueIUAnalyzer.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/UniqueIUAnalyzer.java new file mode 100644 index 000000000..8e589bf05 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/UniqueIUAnalyzer.java @@ -0,0 +1,38 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.analyzer; + +import java.util.HashSet; +import java.util.Set; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.tools.analyzer.IUAnalyzer; + +/** + * This service checks that each IU is unique in a given repository. + */ +public class UniqueIUAnalyzer extends IUAnalyzer { + + Set<String> versionedNames = null; + + public void analyzeIU(IInstallableUnit iu) { + // Create a unique name / version pair and cache it + String uniqueID = iu.getId() + ":" + iu.getVersion().toString(); + if (versionedNames.contains(uniqueID)) { + error(iu, "[ERROR]" + iu.getId() + " with version: " + iu.getVersion() + " already exists in the repository"); + return; + } + versionedNames.add(uniqueID); + } + + public void preAnalysis(IMetadataRepository repo) { + versionedNames = new HashSet<String>(); + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/UnzipFeatureJarAnalyzer.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/UnzipFeatureJarAnalyzer.java new file mode 100644 index 000000000..bb0d2193a --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/UnzipFeatureJarAnalyzer.java @@ -0,0 +1,49 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.analyzer; + +import org.eclipse.equinox.p2.metadata.ITouchpointData; +import org.eclipse.equinox.p2.metadata.ITouchpointInstruction; + +import java.util.List; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.tools.analyzer.IUAnalyzer; + +/** + * This service checks that each Feature Jar IU has the unzip touchpoint + */ +public class UnzipFeatureJarAnalyzer extends IUAnalyzer { + + public void analyzeIU(IInstallableUnit iu) { + if (iu.getId().indexOf("feature.jar") > -1) { + List<ITouchpointData> touchpointData = iu.getTouchpointData(); + if (touchpointData.size() == 0) { + error(iu, "[ERROR] No unzip touchpoint for: " + iu.getId()); + } else { + boolean found = false; + for (int i = 0; i < touchpointData.size(); i++) { + ITouchpointInstruction instruction = touchpointData.get(i).getInstruction("zipped"); + if (instruction.getBody().equals("true")) + found = true; + } + if (!found) { + error(iu, "[ERROR] No unzip touchpoint for: " + iu.getId()); + } + } + } + + } + + public void preAnalysis(IMetadataRepository repository) { + // Do nothing + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/VersionAnalyzer.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/VersionAnalyzer.java new file mode 100644 index 000000000..81a90bdc7 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/analyzer/VersionAnalyzer.java @@ -0,0 +1,43 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.analyzer; + +import org.eclipse.equinox.p2.metadata.Version; + +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.tools.analyzer.IUAnalyzer; + +/** + * This service checks that each IU has a proper version number + * 1. No 0.0.0 + * 2. No x.y.z.qualifier (each qualifier has been replaced) + */ +public class VersionAnalyzer extends IUAnalyzer { + + public void analyzeIU(IInstallableUnit iu) { + if (iu.getVersion().equals(Version.emptyVersion)) { + error(iu, "[ERROR] IU: " + iu.getId() + " has not replaced its qualifiier"); + return; + } + if (iu.getVersion().isOSGiCompatible()) { + String qualifier = Version.toOSGiVersion(iu.getVersion()).getQualifier(); + if (qualifier != null && qualifier.equals("qualifier")) { + error(iu, "[ERROR] IU: " + iu.getId() + " has not replaced its qualifiier"); + return; + } + } + } + + public void preAnalysis(IMetadataRepository repo) { + // Do nothing + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties index 6b07d7fc7..708aacfd7 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties @@ -16,6 +16,10 @@ CompositeRepository_default_artifactRepo_name=Composite Artifact Repository CompositeRepository_default_metadataRepo_name=Composite Artifact Repository CompositeRepositoryApplication_failedComparator=Artifact repository failed test with comparator: {0} +info_noMD5Infomation=No MD5 information available for the artifact [{0}]. +info_noMD5InRepository=The repository {0} does not contain MD5 information for artifact [{1}]. +warning_differentMD5=The repositories {0} and {1} have different MD5 sums for the artifact [{2}]. + no_artifactRepo_manager=Unable to acquire artifact repository manager service. no_metadataRepo_manager=Unable to acquire metadata repository manager service. no_package_admin=Unable to acquire package admin service. @@ -27,12 +31,9 @@ skippingInvalidFilter=Invalid filter format, skipping {0}. MirrorApplication_artifactDestinationNoSource=Destination artifact repository specified without a corresponding source artifact repository. MirrorApplication_metadataDestinationNoSource=Destination metadata repository specified without a corresponding source metadata repository. -MirrorApplication_missingIU=Missing: {0} -MirrorApplication_missingSourceForIUs=Unable to locate source repository for IUs MirrorApplication_no_IUs=No IUs specified and no IUs obtained from metadata repositories. MirrorApplication_set_source_repositories=Need to set the source repository location(s). -MirrorApplication_validateAndMirrorProblems=Problems occurred during validation and mirroring -ProcessRepo_location_not_url=Repository location {0} must be a URL. +ProcessRepo_location_not_url=Repository location {0} must be a URI. ProcessRepo_must_be_local=Repository must be local: {0} @@ -44,7 +45,19 @@ exception_invalidSource=Invalid source repository location: {0}. exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}. exception_notLocalFileRepo= {0} is not a local file based repository. exception_noEngineService=Unable to acquire engine service. +exception_noPlannerService=Unable to acquire planner service. +exception_loadingRepository=Exception while loading repository. exception_needIUsOrNonEmptyRepo=Need to specify either a non-empty source metadata repository or a valid list of IUs. exception_needDestinationRepo=Need to set the destination artifact repository location. exception_onlyOneComparator=Only one comparator should be defined. -Repo2RunnableTask_errorTransforming=Error occurred while transforming repository.
\ No newline at end of file +Repo2RunnableTask_errorTransforming=Error occurred while transforming repository: {0}. + +message_mirroringStatus = Messages while mirroring artifact descriptors. +Mirroring_compareAndDownload=Compare and download of {0} from baseline. +mirror_alreadyExists=Artifact: {0} already exists in repository: {1}. +Mirroring_noMatchingDescriptor=Could not match descriptor for compare +Mirroring_ValidationError=Error occurred while validating mirror. +Mirroring_missingDescriptor=Missing descriptor: {0}. +Mirroring_differentDescriptorProperty=Descriptor {0} has different properties for {1}, source: {2}, destination: {3}. + +invalidComparatorId={0} is not a valid comparator id.
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/analyzer/IIUAnalyzer.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/analyzer/IIUAnalyzer.java new file mode 100644 index 000000000..f1dae6c8d --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/analyzer/IIUAnalyzer.java @@ -0,0 +1,38 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.repository.tools.analyzer; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; + +/** + * The IUAnalaysis Interface. + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * + * Clients are encouraged to extend IUAnalysis, an abstract class that implements + * this interface. + * + * @since 2.0 + * + */ +public interface IIUAnalyzer { + + public static final String ID = "org.eclipse.equinox.p2.repository.tools.verifier"; //$NON-NLS-1$ + + public void preAnalysis(IMetadataRepository repository); + + public IStatus postAnalysis(); + + public void analyzeIU(IInstallableUnit iu); + +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/analyzer/IUAnalyzer.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/analyzer/IUAnalyzer.java new file mode 100644 index 000000000..4d5bc0ca3 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/analyzer/IUAnalyzer.java @@ -0,0 +1,46 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.repository.tools.analyzer; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.p2.internal.repository.tools.Activator; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; + +/** + * An abstract base class for the Analyzer. Clients are encouraged to extends this + * class when defining IU Analysis extension points. + * + */ +public abstract class IUAnalyzer implements IIUAnalyzer { + + private List<IStatus> errors = null; + private String analyzerName; + + public void setName(String name) { + this.analyzerName = name; + } + + protected void error(IInstallableUnit iu, String error) { + if (errors == null) + errors = new ArrayList<IStatus>(); + errors.add(new Status(IStatus.ERROR, Activator.ID, error)); + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.repository.tools.verifier.IIUAnalysis#postAnalysis() + */ + public IStatus postAnalysis() { + if (errors == null || errors.size() == 0) + return Status.OK_STATUS; + return new MultiStatus(Activator.ID, IStatus.ERROR, errors.toArray(new IStatus[errors.size()]), analyzerName, null); + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/analyzer/RepositoryAnalyzer.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/analyzer/RepositoryAnalyzer.java new file mode 100644 index 000000000..f3e208ec1 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/analyzer/RepositoryAnalyzer.java @@ -0,0 +1,72 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.repository.tools.analyzer; + +import java.util.Iterator; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.p2.internal.repository.tools.Activator; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; + +/** + * + */ +public class RepositoryAnalyzer { + + private final IMetadataRepository[] repositories; + + public RepositoryAnalyzer(IMetadataRepository[] repositories) { + this.repositories = repositories; + } + + public IStatus analyze(IProgressMonitor monitor) { + MultiStatus result = new MultiStatus(Activator.ID, IStatus.OK, null, null); + + SubMonitor sub = SubMonitor.convert(monitor, repositories.length * 2); + IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(IIUAnalyzer.ID); + + for (int i = 0; i < repositories.length; i++) { + IQueryResult<IInstallableUnit> queryResult = repositories[i].query(InstallableUnitQuery.ANY, sub); + + SubMonitor repositoryMonitor = SubMonitor.convert(sub, IProgressMonitor.UNKNOWN); + for (int j = 0; j < config.length; j++) { + try { + IIUAnalyzer verifier = (IIUAnalyzer) config[j].createExecutableExtension("class"); //$NON-NLS-1$ + String analyizerName = config[j].getAttribute("name"); //$NON-NLS-1$ + if (verifier instanceof IUAnalyzer) { + ((IUAnalyzer) verifier).setName(analyizerName); + } + verifier.preAnalysis(repositories[i]); + Iterator<IInstallableUnit> iter = queryResult.iterator(); + while (iter.hasNext()) { + IInstallableUnit iu = iter.next(); + verifier.analyzeIU(iu); + } + IStatus postAnalysisResult = verifier.postAnalysis(); + if (postAnalysisResult == null) + postAnalysisResult = new Status(IStatus.OK, Activator.ID, analyizerName); + if (postAnalysisResult.isOK() && !postAnalysisResult.isMultiStatus()) + postAnalysisResult = new Status(IStatus.OK, Activator.ID, analyizerName); + result.add(postAnalysisResult); + } catch (CoreException e) { + if (e.getCause() instanceof ClassNotFoundException) { + result.add(new Status(IStatus.ERROR, Activator.ID, "Cannot find: " + config[j].getAttribute("class"))); + } else + e.printStackTrace(); + } + } + repositoryMonitor.done(); + } + sub.done(); + return result; + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/comparator/ArtifactComparatorFactory.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/comparator/ArtifactComparatorFactory.java new file mode 100644 index 000000000..522fc9ac3 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/comparator/ArtifactComparatorFactory.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Compeople AG (Stefan Liebig) - various ongoing maintenance + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.tools.comparator; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.RegistryFactory; +import org.eclipse.equinox.internal.p2.artifact.repository.Messages; +import org.eclipse.osgi.util.NLS; + +public class ArtifactComparatorFactory { + private static final String comparatorPoint = "org.eclipse.equinox.p2.artifact.repository.artifactComparators"; //$NON-NLS-1$ + private static final String ATTR_ID = "id"; //$NON-NLS-1$ + private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ + + public static IArtifactComparator getArtifactComparator(String comparatorID) { + IConfigurationElement[] extensions = RegistryFactory.getRegistry().getConfigurationElementsFor(comparatorPoint); + + IConfigurationElement element = null; + if (comparatorID == null && extensions.length > 0) { + element = extensions[0]; //just take the first one + } else { + for (int i = 0; i < extensions.length; i++) { + if (extensions[i].getAttribute(ATTR_ID).equals(comparatorID)) { + element = extensions[i]; + break; + } + } + } + if (element != null) { + try { + Object execExt = element.createExecutableExtension(ATTR_CLASS); + if (execExt instanceof IArtifactComparator) + return (IArtifactComparator) execExt; + } catch (Exception e) { + //fall through + } + } + + if (comparatorID != null) + throw new IllegalArgumentException(NLS.bind(Messages.exception_comparatorNotFound, comparatorID)); + throw new IllegalArgumentException(Messages.exception_noComparators); + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/comparator/IArtifactComparator.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/comparator/IArtifactComparator.java new file mode 100644 index 000000000..5197395ae --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/repository/tools/comparator/IArtifactComparator.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.p2.repository.tools.comparator; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; + +public interface IArtifactComparator { + + /** + * Compare 2 equivalent IArtifactDescriptors from different repositories. + * + * IArtifactDescriptors with the same id and version should represent the same + * set of bytes. The comparator should ensure this is true and return an error + * or warning otherwise. + * + * @param source - The source IArtifactRepository + * @param sourceDescriptor - The IArtifactDescriptor from the source repository + * @param destination - The target IArtifactRepository + * @param destDescriptor - The IArtifactDescriptor from the target repository + * + * @return IStatus + */ + public IStatus compare(IArtifactRepository source, IArtifactDescriptor sourceDescriptor, IArtifactRepository destination, IArtifactDescriptor destDescriptor); +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java index 372a2929f..083755166 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 IBM Corporation and others. + * Copyright (c) 2009, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,10 +10,6 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools.tasks; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector; - -import org.eclipse.equinox.internal.provisional.p2.metadata.query.Query; - import java.io.File; import java.net.URI; import java.net.URISyntaxException; @@ -22,17 +18,18 @@ import org.apache.tools.ant.*; import org.apache.tools.ant.types.FileSet; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.URIUtil; -import org.eclipse.equinox.internal.p2.artifact.repository.ant.AntMirrorLog; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; import org.eclipse.equinox.p2.internal.repository.tools.*; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.query.IQuery; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.osgi.util.NLS; public abstract class AbstractRepositoryTask extends Task { protected static final String ANT_PREFIX = "${"; //$NON-NLS-1$ protected AbstractApplication application; - protected List iuTasks = new ArrayList(); - protected List sourceRepos = new ArrayList(); - protected List destinations = new ArrayList(); + protected List<IUDescription> iuTasks = new ArrayList<IUDescription>(); + protected List<FileSet> sourceRepos = new ArrayList<FileSet>(); + protected List<DestinationRepository> destinations = new ArrayList<DestinationRepository>(); protected void addMetadataSourceRepository(URI repoLocation) { RepositoryDescriptor source = new RepositoryDescriptor(); @@ -105,13 +102,11 @@ public abstract class AbstractRepositoryTask extends Task { * Add source repositories to mirror from */ public void addConfiguredSource(RepositoryList sourceList) { - for (Iterator iter = sourceList.getRepositoryList().iterator(); iter.hasNext();) { - DestinationRepository repo = (DestinationRepository) iter.next(); + for (DestinationRepository repo : sourceList.getRepositoryList()) { application.addSource(repo.getDescriptor()); } - for (Iterator iter = sourceList.getFileSetList().iterator(); iter.hasNext();) { - FileSet fileSet = (FileSet) iter.next(); + for (FileSet fileSet : sourceList.getFileSetList()) { sourceRepos.add(fileSet); // Added to the application later through prepareSourceRepos } @@ -124,14 +119,15 @@ public abstract class AbstractRepositoryTask extends Task { protected void prepareSourceRepos() { if (sourceRepos == null || sourceRepos.isEmpty()) return; - for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) { + for (Iterator<FileSet> iter = sourceRepos.iterator(); iter.hasNext();) { RepositoryFileSet fileset = (RepositoryFileSet) iter.next(); if (fileset.getRepoLocation() != null) { - //TODO depreciate if (!fileset.getRepoLocation().startsWith(ANT_PREFIX)) { - addArtifactSourceRepository(fileset.getRepoLocationURI()); - addMetadataSourceRepository(fileset.getRepoLocationURI()); + if (fileset.isArtifact()) + addArtifactSourceRepository(fileset.getRepoLocationURI()); + if (fileset.isMetadata()) + addMetadataSourceRepository(fileset.getRepoLocationURI()); } } else if (fileset.getDir() != null) { DirectoryScanner scanner = fileset.getDirectoryScanner(getProject()); @@ -160,22 +156,21 @@ public abstract class AbstractRepositoryTask extends Task { sourceRepos.clear(); } - protected List prepareIUs() { + protected List<IInstallableUnit> prepareIUs() { if (iuTasks == null || iuTasks.isEmpty()) return null; IMetadataRepository repository = application.getCompositeMetadataRepository(); - List result = new ArrayList(); - for (Iterator iter = iuTasks.iterator(); iter.hasNext();) { - IUDescription iu = (IUDescription) iter.next(); - Query iuQuery = iu.createQuery(); - Collector collector = new Collector(); + List<IInstallableUnit> result = new ArrayList<IInstallableUnit>(); + for (IUDescription iu : iuTasks) { + IQuery<IInstallableUnit> iuQuery = iu.createQuery(); - repository.query(iuQuery, collector, null); + Iterator<IInstallableUnit> queryResult = repository.query(iuQuery, null).iterator(); - if (iu.isRequired() && collector.isEmpty()) + if (iu.isRequired() && !queryResult.hasNext()) throw new BuildException(NLS.bind(Messages.AbstractRepositoryTask_unableToFind, iu.toString())); - result.addAll(collector.toCollection()); + while (queryResult.hasNext()) + result.add(queryResult.next()); } return result; } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AntMirrorLog.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AntMirrorLog.java new file mode 100644 index 000000000..5c7d04d08 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AntMirrorLog.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.tasks; + +import org.eclipse.equinox.p2.internal.repository.mirroring.IArtifactMirrorLog; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.artifact.repository.Messages; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; + +public class AntMirrorLog implements IArtifactMirrorLog { + + private boolean consoleMessage = false; + private Method log; + private Object task; + + public AntMirrorLog(Object task) throws NoSuchMethodException { + this.task = task; + try { + log = task.getClass().getMethod("log", new Class[] {String.class, int.class}); //$NON-NLS-1$ + } catch (SecurityException e) { + exceptionOccurred(null, e); + } + } + + public void log(IArtifactDescriptor descriptor, IStatus status) { + log(descriptor.toString(), status.getSeverity()); + log(status); + } + + public void log(IStatus status) { + int severity = status.getSeverity(); + // Log the status message + log(status.getMessage(), severity); + // Log the exception if applicable + if (status.getException() != null) + log(status.getException().getMessage(), severity); + + // Log any children of this status + IStatus[] nestedStatus = status.getChildren(); + if (nestedStatus != null) + for (int i = 0; i < nestedStatus.length; i++) + log(nestedStatus[i]); + } + + public void close() { + // nothing to do here + } + + /* + * Log a message to the Ant Task + */ + private void log(String message, int statusSeverity) { + try { + log.invoke(task, new Object[] {message, new Integer(mapLogLevels(statusSeverity))}); + } catch (IllegalArgumentException e) { + exceptionOccurred(message, e); + } catch (IllegalAccessException e) { + exceptionOccurred(message, e); + } catch (InvocationTargetException e) { + exceptionOccurred(message, e); + } + } + + /* + * Show an error message if this the first time, and print status messages. + */ + private void exceptionOccurred(String message, Exception e) { + if (!consoleMessage) { + System.err.println(Messages.MirrorLog_Exception_Occurred); + e.printStackTrace(System.err); + System.err.println(Messages.MirrorLog_Console_Log); + consoleMessage = true; + } + if (message != null) + System.out.println(message); + } + + /** + * Copied from AntLogAdapter in pde build. + */ + private int mapLogLevels(int iStatusLevel) { + switch (iStatusLevel) { + case IStatus.ERROR : + return 0; + case IStatus.OK : + return 2; + case IStatus.INFO : + return 2; + case IStatus.WARNING : + return 1; + default : + return 1; + } + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java index f1e8e9e9c..4560fe96f 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java @@ -10,13 +10,18 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools.tasks; -import java.util.Iterator; +import java.net.URI; +import java.net.URISyntaxException; import org.apache.tools.ant.BuildException; import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.internal.repository.tools.CompositeRepositoryApplication; +import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; public class CompositeRepositoryTask extends AbstractRepositoryTask { + private static String COMPOSITE_REMOVE = "p2.composite.artifact.repository.remove"; //$NON-NLS-1$ + private static String COMPOSITE_ADD = "p2.composite.artifact.repository.add"; //$NON-NLS-1$ public CompositeRepositoryTask() { application = new CompositeRepositoryApplication(); @@ -40,8 +45,7 @@ public class CompositeRepositoryTask extends AbstractRepositoryTask { * Add the listed repositories to the composite repository */ public void addConfiguredAdd(RepositoryList list) { - for (Iterator iter = list.getRepositoryList().iterator(); iter.hasNext();) { - DestinationRepository repo = (DestinationRepository) iter.next(); + for (DestinationRepository repo : list.getRepositoryList()) { ((CompositeRepositoryApplication) application).addChild(repo.getDescriptor()); } } @@ -50,8 +54,7 @@ public class CompositeRepositoryTask extends AbstractRepositoryTask { * Remove the listed repositories from the composite repository */ public void addConfiguredRemove(RepositoryList list) { - for (Iterator iter = list.getRepositoryList().iterator(); iter.hasNext();) { - DestinationRepository repo = (DestinationRepository) iter.next(); + for (DestinationRepository repo : list.getRepositoryList()) { ((CompositeRepositoryApplication) application).removeChild(repo.getDescriptor()); } } @@ -66,4 +69,35 @@ public class CompositeRepositoryTask extends AbstractRepositoryTask { public void setValidate(String value) { ((CompositeRepositoryApplication) application).setComparator(value); } + + /* p2.composite.artifact.repository.add + * p2.composite.artifact.repository.remove*/ + public void setLocation(String value) { + super.setDestination(value); + } + + /* p2.composite.artifact.repository.add + * p2.composite.artifact.repository.remove*/ + public void setChild(String value) throws URISyntaxException { + URI childURI = URIUtil.fromString(value); + RepositoryDescriptor repo = new RepositoryDescriptor(); + repo.setLocation(childURI); + + if (getTaskName().equals(COMPOSITE_ADD)) + ((CompositeRepositoryApplication) application).addChild(repo); + else if (getTaskName().equals(COMPOSITE_REMOVE)) + ((CompositeRepositoryApplication) application).removeChild(repo); + } + + /* p2.composite.artifact.repository.add */ + public void setComparatorID(String value) { + if (value != null && !value.startsWith(ANT_PREFIX)) + ((CompositeRepositoryApplication) application).setComparator(value); + } + + /* p2.composite.artifact.repository.remove */ + public void setAllChildren(String value) { + if (value != null && !value.startsWith(ANT_PREFIX)) + ((CompositeRepositoryApplication) application).setRemoveAll(Boolean.valueOf(value).booleanValue()); + } } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CreateCompositeArtifactRepositoryTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CreateCompositeArtifactRepositoryTask.java new file mode 100644 index 000000000..d2a4a481a --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CreateCompositeArtifactRepositoryTask.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.tasks; + +import org.eclipse.equinox.p2.core.ProvisionException; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.equinox.internal.p2.artifact.repository.Activator; +import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; + +/** + * Ant task for creating a new composite artifact repository. + */ +public class CreateCompositeArtifactRepositoryTask extends Task { + + URI location; // desired location of the composite repository + String name = "Composite Artifact Repository"; + boolean compressed = true; + boolean failOnExists = false; // should we fail if a repo already exists? + Map<String, String> properties = new HashMap<String, String>(); + + /* (non-Javadoc) + * @see org.apache.tools.ant.Task#execute() + */ + public void execute() { + validate(); + IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.SERVICE_NAME); + if (manager == null) + throw new BuildException("Unable to aquire artifact repository manager service."); + + // remove the repo first. + manager.removeRepository(location); + + // first try and load to see if one already exists at that location. + // if we have an already existing repository at that location, then throw an error + // if the user told us to + try { + IArtifactRepository repository = manager.loadRepository(location, null); + if (repository instanceof CompositeArtifactRepository) { + if (failOnExists) + throw new BuildException("Composite repository already exists at location: " + location); + return; + } else { + // we have a non-composite repo at this location. that is ok because we can co-exist. + } + } catch (ProvisionException e) { + // re-throw the exception if we got anything other than "repo not found" + if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND) + throw new BuildException("Exception while trying to read repository at: " + location, e); + } + + // set the properties + if (compressed) + properties.put(IRepository.PROP_COMPRESSED, Boolean.toString(true)); + + // create the repository + try { + manager.createRepository(location, name, IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, properties); + } catch (ProvisionException e) { + throw new BuildException("Error occurred while creating composite artifact repository.", e); + } + } + + /* + * Perform basic sanity checking of some of the parameters. + */ + private void validate() { + if (location == null) + throw new BuildException("Must specify repository location."); + if (name == null) + throw new BuildException("Must specify a repository name."); + } + + /* + * Set the name of the composite repository. + */ + public void setName(String value) { + name = value; + } + + /* + * Set the location of the repository. + */ + public void setLocation(String value) throws URISyntaxException { + location = URIUtil.fromString(value); + } + + /* + * Set a value indicating whether or not the repository should be compressed. + */ + public void setCompressed(boolean value) { + compressed = value; + } + + /* + * Set whether or not we should fail the operation if a repository + * already exists at the location. + */ + public void setFailOnExists(boolean value) { + failOnExists = value; + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java index 70a91b01c..f02a2b74a 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java @@ -10,11 +10,18 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools.tasks; +import org.eclipse.equinox.p2.metadata.Version; + import java.util.*; import org.apache.tools.ant.types.DataType; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.*; +import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils; +import org.eclipse.equinox.internal.p2.metadata.query.IUPropertyQuery; +import org.eclipse.equinox.internal.p2.metadata.query.LatestIUVersionQuery; import org.eclipse.equinox.p2.internal.repository.tools.Activator; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.query.IQuery; +import org.eclipse.equinox.p2.query.PipedQuery; import org.osgi.framework.Filter; import org.osgi.framework.InvalidSyntaxException; @@ -100,29 +107,32 @@ public class IUDescription extends DataType { return buffer.toString(); } - public Query createQuery() { - List queries = new ArrayList(); + public IQuery<IInstallableUnit> createQuery() { + List<IQuery<IInstallableUnit>> queries = new ArrayList<IQuery<IInstallableUnit>>(); if (id != null) { if (version == null || version.length() == 0) { // Get the latest version of the iu queries.add(new InstallableUnitQuery(id)); - queries.add(new LatestIUVersionQuery()); + queries.add(new LatestIUVersionQuery<IInstallableUnit>()); } else { Version iuVersion = Version.parseVersion(version); queries.add(new InstallableUnitQuery(id, iuVersion)); } } - Query iuQuery = processQueryString(); + IQuery<IInstallableUnit> iuQuery = processQueryString(); if (iuQuery != null) queries.add(iuQuery); if (queries.size() == 1) - return (Query) queries.get(0); - return new CompositeQuery((Query[]) queries.toArray(new Query[queries.size()])); + return queries.get(0); + + @SuppressWarnings("unchecked") + IQuery<IInstallableUnit> query = new PipedQuery<IInstallableUnit>(queries.toArray(new IQuery[queries.size()])); + return query; } - private Query processQueryString() { + private IQuery<IInstallableUnit> processQueryString() { if (queryString == null) return null; int startIdx = queryString.indexOf('['); @@ -130,10 +140,10 @@ public class IUDescription extends DataType { if (startIdx == -1 || endIdx == -1 || endIdx < startIdx) return null; String element = queryString.substring(0, startIdx); - Map attributes = processQueryAttributes(queryString.substring(startIdx + 1, endIdx)); + Map<String, String> attributes = processQueryAttributes(queryString.substring(startIdx + 1, endIdx)); if (element.equals(QUERY_PROPERTY)) { - String name = (String) attributes.get(QUERY_NAME); - String value = (String) attributes.get(QUERY_VALUE); + String name = attributes.get(QUERY_NAME); + String value = attributes.get(QUERY_VALUE); if (name == null) return null; return new IUPropertyQuery(name, value); @@ -142,11 +152,11 @@ public class IUDescription extends DataType { return null; } - private Map processQueryAttributes(String attributes) { + private Map<String, String> processQueryAttributes(String attributes) { if (attributes == null || attributes.length() == 0) - return Collections.EMPTY_MAP; + return CollectionUtils.emptyMap(); - Map result = new HashMap(); + Map<String, String> result = new HashMap<String, String>(); int start = 0; int idx = 0; while ((idx = attributes.indexOf('@', start)) > -1) { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorArtifactsTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorArtifactsTask.java new file mode 100644 index 000000000..f75497bf4 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorArtifactsTask.java @@ -0,0 +1,180 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.tasks; + +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication; +import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; + +/** + * Ant task for running the artifact repository mirroring application. + */ +public class MirrorArtifactsTask extends Task { + URI source; + URI destination; + String destinationName; + URI baseline; // location of known good repository for compare against (optional) + File mirrorLog; // file to log mirror output to (optional) + File comparatorLog; // file to comparator output to (optional) + String comparatorID; // specifies a comparator (optional) + String writeMode; + boolean compare = false; + boolean ignoreErrors = false; + boolean raw = false; // use raw artifact descriptors? + boolean verbose = false; + + /* (non-Javadoc) + * @see org.apache.tools.ant.Task#execute() + */ + public void execute() { + // Compare against if baseline specified + RepositoryDescriptor destinationRepo = new RepositoryDescriptor(); + destinationRepo.setName(destinationName); + destinationRepo.setLocation(destination); + destinationRepo.setKind(RepositoryDescriptor.KIND_ARTIFACT); + if (writeMode != null && writeMode.equals("clean")) //$NON-NLS-1$ + destinationRepo.setAppend(false); + + RepositoryDescriptor sourceRepo = new RepositoryDescriptor(); + sourceRepo.setLocation(source); + sourceRepo.setKind(RepositoryDescriptor.KIND_ARTIFACT); + + MirrorApplication app = new MirrorApplication(); + app.addDestination(destinationRepo); + app.addSource(sourceRepo); + app.setRaw(raw); + app.setIgnoreErrors(ignoreErrors); + app.setVerbose(verbose); + app.setCompare(compare); + app.setComparatorID(comparatorID); + app.setBaseline(baseline); + if (comparatorLog != null) + app.setComparatorLog(comparatorLog); + if (mirrorLog != null) + app.setLog(mirrorLog); + else { + try { + app.setLog(new AntMirrorLog(this)); + } catch (NoSuchMethodException e) { + //shouldn't happen + } + } + + try { + app.run(null); + } catch (Exception e) { + throw new BuildException("Exception while running mirror application.", e); + } + } + + /* + * Set the location of the source. + */ + public void setSource(String value) { + try { + source = URIUtil.fromString(value); + } catch (URISyntaxException e) { + throw new BuildException(e); + } + } + + /* + * Set the location of the destination. + */ + public void setDestination(String value) { + try { + destination = URIUtil.fromString(value); + } catch (URISyntaxException e) { + throw new BuildException(e); + } + } + + /* + * Set the name of the destination repository. + */ + public void setDestinationName(String value) { + destinationName = value; + } + + /* + * Set the location of the baseline repository. (used in comparison) + */ + public void setBaseline(String value) { + try { + baseline = URIUtil.fromString(value); + } catch (URISyntaxException e) { + throw new BuildException(e); + } + compare = true; + } + + /* + * Set the identifier of the comparator to use. + */ + public void setComparatorID(String value) { + comparatorID = value; + compare = true; + } + + /* + * Set the location of the comparator log + */ + public void setComparatorLog(String value) { + comparatorLog = new File(value); + } + + /* + * Set the write mode. (e.g. clean or append) + */ + public void setWriteMode(String value) { + writeMode = value; + } + + /* + * Set the log location if applicable + */ + public void setLog(String value) { + mirrorLog = new File(value); + } + + /* + * Set whether or not the application should be calling a comparator when mirroring. + */ + public void setCompare(boolean value) { + compare = value; + } + + /* + * Set whether or not we should ignore errors when running the mirror application. + */ + public void setIgnoreErrors(boolean value) { + ignoreErrors = value; + } + + /* + * Set whether or not the the artifacts are raw. + */ + public void setRaw(boolean value) { + raw = value; + } + + /* + * Set whether or not the mirror application should be run in verbose mode. + */ + public void setVerbose(boolean value) { + verbose = value; + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorMetadataTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorMetadataTask.java new file mode 100644 index 000000000..f4350f3da --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorMetadataTask.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.tasks; + +import org.eclipse.equinox.p2.core.ProvisionException; + +import java.net.URI; +import java.net.URISyntaxException; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication; +import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; + +/** + * Ant task for running the metadata mirror application. + */ +public class MirrorMetadataTask extends Task { + URI source; + URI destination; + String destinationName; + String writeMode; + + /* (non-Javadoc) + * @see org.apache.tools.ant.Task#execute() + */ + public void execute() { + RepositoryDescriptor destinationRepo = new RepositoryDescriptor(); + destinationRepo.setName(destinationName); + destinationRepo.setLocation(destination); + destinationRepo.setKind(RepositoryDescriptor.KIND_METADATA); + if (writeMode != null && writeMode.equals("clean")) //$NON-NLS-1$ + destinationRepo.setAppend(false); + + RepositoryDescriptor sourceRepo = new RepositoryDescriptor(); + sourceRepo.setLocation(source); + sourceRepo.setKind(RepositoryDescriptor.KIND_METADATA); + + MirrorApplication app = new MirrorApplication(); + app.addDestination(destinationRepo); + app.addSource(sourceRepo); + try { + IStatus result = app.run(null); + if (result.getSeverity() != IStatus.OK) + log(result.getMessage()); + } catch (ProvisionException e) { + throw new BuildException(e); + } + } + + /* + * Set the source location. + */ + public void setSource(String value) { + try { + source = URIUtil.fromString(value); + } catch (URISyntaxException e) { + throw new BuildException(e); + } + } + + /* + * Set the destination location. + */ + public void setDestination(String value) { + try { + destination = URIUtil.fromString(value); + } catch (URISyntaxException e) { + throw new BuildException(e); + } + } + + /* + * Set the destination name. + */ + public void setDestinationName(String value) { + destinationName = value; + } + + /* + * Set the write mode for the application. (e.g. clean or append) + */ + public void setWriteMode(String value) { + writeMode = value; + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java index fceaaf32a..71f2b8bda 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java @@ -10,14 +10,15 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools.tasks; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.File; import java.util.List; import org.apache.tools.ant.BuildException; import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.p2.artifact.repository.ant.AntMirrorLog; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.p2.internal.repository.tools.Messages; import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; public class MirrorTask extends AbstractRepositoryTask { @@ -51,7 +52,7 @@ public class MirrorTask extends AbstractRepositoryTask { prepareSourceRepos(); application.initializeRepos(null); - List ius = prepareIUs(); + List<IInstallableUnit> ius = prepareIUs(); application.setSourceIUs(ius); IStatus result = application.run(null); if (result.matches(IStatus.ERROR)) diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ProcessRepoTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ProcessRepoTask.java index 9e8947335..aa069e184 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ProcessRepoTask.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ProcessRepoTask.java @@ -12,7 +12,6 @@ package org.eclipse.equinox.p2.internal.repository.tools.tasks; import java.io.File; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import org.apache.tools.ant.BuildException; @@ -20,7 +19,7 @@ import org.apache.tools.ant.Task; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.URIUtil; import org.eclipse.equinox.internal.p2.jarprocessor.ant.JarProcessorTask; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; +import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.internal.repository.tools.*; import org.eclipse.osgi.util.NLS; @@ -64,7 +63,8 @@ public class ProcessRepoTask extends Task { public void execute() throws BuildException { File file = URIUtil.toFile(repository); if (file == null || !file.exists()) { - throw new BuildException(NLS.bind(Messages.ProcessRepo_must_be_local, repository.toString())); + throw new BuildException(NLS.bind( + Messages.ProcessRepo_must_be_local, repository.toString())); } if (pack | repack | signing != null) { if (jarProcessor == null) @@ -76,7 +76,8 @@ public class ProcessRepoTask extends Task { jarProcessor.setStorepass(signing.storepass); jarProcessor.setUnsign(signing.unsign); - if (signing.alias != null && signing.alias.length() > 0 && !signing.alias.startsWith("${")) //$NON-NLS-1$ + if (signing.alias != null && signing.alias.length() > 0 + && !signing.alias.startsWith("${")) //$NON-NLS-1$ jarProcessor.setSign(true); } jarProcessor.setPack(pack); @@ -103,9 +104,6 @@ public class ProcessRepoTask extends Task { } catch (ProvisionException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } @@ -113,7 +111,8 @@ public class ProcessRepoTask extends Task { try { this.repository = URIUtil.fromString(repository); } catch (URISyntaxException e) { - throw new IllegalArgumentException(NLS.bind(Messages.ProcessRepo_location_not_url, repository)); + throw new IllegalArgumentException(NLS.bind( + Messages.ProcessRepo_location_not_url, repository)); } } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java index c766504b8..531134c24 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java @@ -14,15 +14,16 @@ import java.util.*; import org.apache.tools.ant.BuildException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; +import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.internal.repository.tools.AbstractApplication; import org.eclipse.equinox.p2.internal.repository.tools.Messages; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.query.IQuery; +import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.osgi.util.NLS; import org.osgi.framework.Filter; import org.osgi.framework.InvalidSyntaxException; @@ -59,20 +60,18 @@ public class RemoveIUTask extends AbstractRepositoryTask { IMetadataRepository repository = application.getDestinationMetadataRepository(); IArtifactRepository artifacts = application.getDestinationArtifactRepository(); - final Set toRemove = new HashSet(); - for (Iterator iter = iuTasks.iterator(); iter.hasNext();) { - IUDescription iu = (IUDescription) iter.next(); - Query iuQuery = iu.createQuery(); + final Set<IInstallableUnit> toRemove = new HashSet<IInstallableUnit>(); + for (IUDescription iu : iuTasks) { + IQuery<IInstallableUnit> iuQuery = iu.createQuery(); - Collector collector = new Collector(); - repository.query(iuQuery, collector, null); + IQueryResult<IInstallableUnit> queryResult = repository.query(iuQuery, null); - if (collector.isEmpty()) + if (queryResult.isEmpty()) getProject().log(NLS.bind(Messages.AbstractRepositoryTask_unableToFind, iu.toString())); else { - for (Iterator iterator = collector.iterator(); iterator.hasNext();) { - IInstallableUnit unit = (IInstallableUnit) iterator.next(); - IArtifactKey[] keys = unit.getArtifacts(); + for (Iterator<IInstallableUnit> iterator = queryResult.iterator(); iterator.hasNext();) { + IInstallableUnit unit = iterator.next(); + Collection<IArtifactKey> keys = unit.getArtifacts(); Filter filter = null; try { filter = iu.getArtifactFilter(); @@ -83,11 +82,11 @@ public class RemoveIUTask extends AbstractRepositoryTask { //we will only remove the metadata if all artifacts were removed boolean removeMetadata = true; - for (int i = 0; i < keys.length; i++) { + for (IArtifactKey key : keys) { if (filter == null) { - artifacts.removeDescriptor(keys[i]); + artifacts.removeDescriptor(key); } else { - IArtifactDescriptor[] descriptors = artifacts.getArtifactDescriptors(keys[i]); + IArtifactDescriptor[] descriptors = artifacts.getArtifactDescriptors(key); for (int j = 0; j < descriptors.length; j++) { if (filter.match(createDictionary(descriptors[j]))) { artifacts.removeDescriptor(descriptors[j]); @@ -104,12 +103,7 @@ public class RemoveIUTask extends AbstractRepositoryTask { } if (toRemove.size() > 0) { - Query removeQuery = new MatchQuery() { - public boolean isMatch(Object candidate) { - return toRemove.contains(candidate); - } - }; - repository.removeInstallableUnits(removeQuery, null); + repository.removeInstallableUnits(toRemove.toArray(new IInstallableUnit[toRemove.size()]), null); } } catch (ProvisionException e) { throw new BuildException(e); @@ -122,8 +116,8 @@ public class RemoveIUTask extends AbstractRepositoryTask { } } - private Dictionary createDictionary(IArtifactDescriptor descriptor) { - Hashtable result = new Hashtable(5); + private Dictionary<String, Object> createDictionary(IArtifactDescriptor descriptor) { + Hashtable<String, Object> result = new Hashtable<String, Object>(5); result.putAll(descriptor.getProperties()); IArtifactKey key = descriptor.getArtifactKey(); result.put(CLASSIFIER, key.getClassifier()); diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java index 8763492a5..f0af711ae 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java @@ -10,13 +10,16 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools.tasks; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.util.List; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.p2.internal.repository.tools.Messages; import org.eclipse.equinox.p2.internal.repository.tools.Repo2Runnable; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.osgi.util.NLS; /** * Ant task which calls the "repo to runnable" application. This application takes an @@ -47,7 +50,7 @@ public class Repo2RunnableTask extends AbstractRepositoryTask { try { prepareSourceRepos(); application.initializeRepos(null); - List ius = prepareIUs(); + List<IInstallableUnit> ius = prepareIUs(); if ((ius == null || ius.size() == 0) && !(application.hasArtifactSources() || application.hasMetadataSources())) throw new BuildException(Messages.exception_needIUsOrNonEmptyRepo); application.setSourceIUs(ius); @@ -56,9 +59,9 @@ public class Repo2RunnableTask extends AbstractRepositoryTask { throw new ProvisionException(result); } catch (ProvisionException e) { if (failOnError) - throw new BuildException(Messages.Repo2RunnableTask_errorTransforming, e); + throw new BuildException(NLS.bind(Messages.Repo2RunnableTask_errorTransforming, null != e.getMessage() ? e.getMessage() : e.toString()), e); /* else */ - getProject().log(Messages.Repo2RunnableTask_errorTransforming, Project.MSG_WARN); + getProject().log(NLS.bind(Messages.Repo2RunnableTask_errorTransforming, null != e.getMessage() ? e.getMessage() : e.toString()), Project.MSG_WARN); getProject().log(e.getMessage(), Project.MSG_WARN); } } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java index c7e88ddf4..79b16675c 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java @@ -16,8 +16,8 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.FileSet; import org.eclipse.core.runtime.URIUtil; import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; +import org.eclipse.equinox.p2.repository.IRepository; public class RepositoryFileSet extends FileSet { public final static int TYPE_ARTIFACT = IRepository.TYPE_ARTIFACT; @@ -47,17 +47,14 @@ public class RepositoryFileSet extends FileSet { } public void setLocation(String value) { - // TODO depreciate myLocation = value; } public String getRepoLocation() { - // TODO depreciate return myLocation; } public URI getRepoLocationURI() { - // TODO depreciate try { return RepositoryHelper.localRepoURIHelper(URIUtil.fromString(getRepoLocation())); } catch (URISyntaxException e) { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java index a76d3218d..8f31ce3a7 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java @@ -12,11 +12,12 @@ package org.eclipse.equinox.p2.internal.repository.tools.tasks; import java.util.ArrayList; import java.util.List; +import org.apache.tools.ant.types.FileSet; public class RepositoryList extends RepositoryFileSet { // TODO this class should extend DataType, currently RepoFileSet to support <source location="xxx" /> - List repositories = new ArrayList(); - List sourceFileSets = new ArrayList(); + List<DestinationRepository> repositories = new ArrayList<DestinationRepository>(); + List<FileSet> sourceFileSets = new ArrayList<FileSet>(); public DestinationRepository createRepository() { DestinationRepository repo = new DestinationRepository(); @@ -30,11 +31,11 @@ public class RepositoryList extends RepositoryFileSet { return fileSet; } - public List getRepositoryList() { + public List<DestinationRepository> getRepositoryList() { return repositories; } - public List getFileSetList() { + public List<FileSet> getFileSetList() { //TODO this should eventually be removed sourceFileSets.add(this); return sourceFileSets; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java index fcd8a6b37..774201a83 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java @@ -56,7 +56,7 @@ public class SlicingOption extends Task { StringTokenizer tok = new StringTokenizer(platformFilter, ","); //$NON-NLS-1$ if (tok.countTokens() != 3) throw new BuildException(NLS.bind(Messages.SlicingOption_invalid_platform, platformFilter)); - Dictionary filter = options.getFilter(); + Dictionary<String, Object> filter = options.getFilter(); filter.put("osgi.os", tok.nextToken().trim()); //$NON-NLS-1$ filter.put("osgi.ws", tok.nextToken().trim()); //$NON-NLS-1$ filter.put("osgi.arch", tok.nextToken().trim()); //$NON-NLS-1$ @@ -68,7 +68,7 @@ public class SlicingOption extends Task { } public void setIncludeFeatures(boolean includeFeatures) { - Dictionary filter = options.getFilter(); + Dictionary<String, Object> filter = options.getFilter(); filter.put("org.eclipse.update.install.features", String.valueOf(includeFeatures)); //$NON-NLS-1$ options.setFilter(filter); } @@ -76,7 +76,7 @@ public class SlicingOption extends Task { public void setFilter(String filterString) { if (filterString == null || filterString.trim().equals("")) //$NON-NLS-1$ return; - Dictionary filter = options.getFilter(); + Dictionary<String, Object> filter = options.getFilter(); StringTokenizer tok = new StringTokenizer(filterString, ","); //$NON-NLS-1$ while (tok.hasMoreTokens()) { String rule = tok.nextToken().trim(); diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ValidateTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ValidateTask.java new file mode 100644 index 000000000..5b3188218 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ValidateTask.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2008, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.tasks; + +import java.net.URI; +import org.apache.tools.ant.BuildException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.artifact.repository.Activator; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.internal.repository.tools.ArtifactRepositoryValidator; +import org.eclipse.equinox.p2.internal.repository.tools.Messages; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; + +/** + * Ant task for validating the contents of a composite artifact repository. + */ +public class ValidateTask extends AbstractRepositoryTask { + + private String comparatorID; // specifies the comparator we want to use. + + /* (non-Javadoc) + * @see org.apache.tools.ant.Task#execute() + */ + public void execute() { + IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.SERVICE_NAME); + if (manager == null) + throw new BuildException(Messages.no_artifactRepo_manager); + + ArtifactRepositoryValidator validator; + try { + validator = new ArtifactRepositoryValidator(comparatorID); + } catch (ProvisionException e) { + throw new BuildException(Messages.invalidComparatorId, e); + } + + IArtifactRepository artifactRepository = null; + for (DestinationRepository repo : destinations) { + URI repoLocation = repo.getDescriptor().getRepoLocation(); + try { + artifactRepository = manager.loadRepository(repoLocation, null); + IStatus result = validator.validateRepository(artifactRepository); + if (!result.isOK()) + throw new BuildException(result.getMessage()); + } catch (ProvisionException e) { + throw new BuildException(Messages.exception_loadingRepository, e); + } + } + } + + /* + * Set the repository location. + */ + public void setLocation(String value) { + super.setDestination(value); + } + + /* + * Set the ID of the comparator. + */ + public void setComparatorID(String value) { + comparatorID = value; + } +} |