Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Daniel2013-12-13 15:47:01 +0000
committerKrzysztof Daniel2013-12-18 10:25:50 +0000
commit2f25b2c24c901026f701d4f1defb7f06f82e339a (patch)
tree1aa2d84cb99c1e4957679ce99f9ac723cee40958
parent73e3365d5687050be42fe7484560230fc36a99be (diff)
downloadrt.equinox.p2-fragmentgeneration.tar.gz
rt.equinox.p2-fragmentgeneration.tar.xz
rt.equinox.p2-fragmentgeneration.zip
[nobug] support fragments generation.fragmentgeneration
This is one giant hack and needs total rewrite, but it would be good if the repo2runnable could write the .info file on the basis of metadata. Change-Id: Iacb22ccdf9e72a9415bb845f1cf2944f59382f0d Signed-off-by: Krzysztof Daniel <kdaniel@redhat.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java115
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties1
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java9
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/Repo2RunnableTaskTests.java40
5 files changed, 157 insertions, 9 deletions
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 47cc723c1..e819ec06f 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
@@ -50,6 +50,7 @@ public class Messages extends NLS {
public static String SlicingOption_invalid_platform;
public static String exception_invalidDestination;
public static String exception_invalidSource;
+ public static String Repo2Runnable_12;
public static String Repo2RunnableTask_errorTransforming;
public static String SlicingOption_invalidFilterFormat;
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 91d6d4236..10b36fbf5 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 IBM Corporation and others.
+ * Copyright (c) 2009, 2013 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
@@ -8,9 +8,11 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Sonatype, Inc. - ongoing development
+ * Red Hat, Inc. - fragment creation
*******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools;
+import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
@@ -23,12 +25,12 @@ 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.*;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.artifact.*;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
+import org.eclipse.osgi.util.NLS;
/**
* The transformer takes an existing p2 repository (local or remote), iterates over
@@ -39,11 +41,14 @@ import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
* @since 1.0
*/
public class Repo2Runnable extends AbstractApplication implements IApplication {
+ private static final String FRAGMENT_INFO_FILE_NAME = "fragment.info"; //$NON-NLS-1$
+ private static final String FRAGMENT_PROFILE_FILE_NAME = "fragment.profile"; //$NON-NLS-1$
private static final String NATIVE_ARTIFACTS = "nativeArtifacts"; //$NON-NLS-1$
private static final String NATIVE_TYPE = "org.eclipse.equinox.p2.native"; //$NON-NLS-1$
private static final String PARM_OPERAND = "operand"; //$NON-NLS-1$
private static final String PARM_PROFILE = "profile"; //$NON-NLS-1$
+ private boolean createFragments;
private boolean flagAsRunnable = false;
protected class CollectNativesAction extends ProvisioningAction {
@@ -149,12 +154,100 @@ public class Repo2Runnable extends AbstractApplication implements IApplication {
setRunnableProperty(destinationArtifactRepository);
// return the resulting status
+
+ if (createFragments) {
+ File parentDir = new File(destinationArtifactRepository.getLocation().toString().substring(5));
+ File pluginsDir = new File(parentDir, "plugins"); //$NON-NLS-1$
+ File fragmentInfo = new File(parentDir, FRAGMENT_INFO_FILE_NAME);
+ BufferedWriter bw = new BufferedWriter(new FileWriter(fragmentInfo));
+ try {
+ Profile p = (Profile) profile;
+ for (Iterator<IInstallableUnit> iterator = processedIUs.iterator(); iterator.hasNext();) {
+ IInstallableUnit unit = iterator.next();
+ boolean featureOrBundle = false;
+ // put in the fragment profile only things that are: bundles, source bundles, features and feature groups.
+ Collection<IProvidedCapability> providedCapabilities = unit.getProvidedCapabilities();
+ for (IProvidedCapability cap : providedCapabilities) {
+ if ("org.eclipse.equinox.p2.eclipse.type".equals(cap.getNamespace())) { //$NON-NLS-1$
+ if ("bundle".equals(cap.getName())) { //$NON-NLS-1$
+ featureOrBundle = true;
+ String line = unit.getId() + "," + unit.getVersion() + ","; //$NON-NLS-1$ //$NON-NLS-2$
+ line += findFile(pluginsDir, unit);
+ line += ",4,false";
+ bw.write(line);
+ bw.write("\n");
+ break;
+ }
+ if ("source".equals(cap.getName())) { //$NON-NLS-1$
+ featureOrBundle = true;
+ break;
+ }
+ if ("feature".equals(cap.getName())) { //$NON-NLS-1$
+ featureOrBundle = true;
+ break;
+ }
+ }
+ }
+ if (Boolean.TRUE.equals(unit.getProperty("org.eclipse.equinox.p2.type.group"))) { //$NON-NLS-1$
+ //this means we have a feature, and we want to have it installed in the profile
+ featureOrBundle = true;
+ }
+ if (featureOrBundle) {
+ p.addInstallableUnit(unit);
+ }
+ }
+ bw.close();
+ Writer w = new Writer(new FileOutputStream(new File(parentDir, FRAGMENT_PROFILE_FILE_NAME)));
+ w.writeProfile(profile);
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
return result;
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
} finally {
// cleanup by removing the temporary profile and unloading the repos which were new
removeProfile(profile);
finalizeRepositories();
}
+ return null;
+ }
+
+ private String findFile(File pluginsDir, IInstallableUnit unit) throws ProvisionException {
+ String pattern = unit.getId() + "_" + unit.getVersion(); //f.e. directory a.b.c_1.0.0 //$NON-NLS-1$
+ File candidate = new File(pluginsDir, pattern);
+ if (candidate.exists()) {
+ return pluginsDir.getName() + File.pathSeparator + pattern;
+ }
+ pattern = unit.getId() + "-" + unit.getVersion(); //f.e. directory (maven style) a.b.c-1.0.0 //$NON-NLS-1$
+ candidate = new File(pluginsDir, pattern);
+ if (candidate.exists()) {
+ return pluginsDir.getName() + File.pathSeparator + pattern;
+ }
+ pattern = unit.getId() + "_" + unit.getVersion() + ".jar"; //f.e. jar a.b.c-1.0.0.jar //$NON-NLS-1$ //$NON-NLS-2$
+ candidate = new File(pluginsDir, pattern);
+ if (candidate.exists()) {
+ return pluginsDir.getName() + File.pathSeparator + pattern;
+ }
+ pattern = unit.getId() + "-" + unit.getVersion() + ".jar"; //f.e. jar (maven style) a.b.c-1.0.0.jar //$NON-NLS-1$ //$NON-NLS-2$
+ candidate = new File(pluginsDir, pattern);
+ if (candidate.exists()) {
+ return pluginsDir.getName() + File.pathSeparator + pattern;
+ }
+ throw new ProvisionException(NLS.bind(Messages.Repo2Runnable_12, unit.getId(), unit.getVersion()));
+ }
+
+ static class Writer extends ProfileWriter {
+
+ public Writer(OutputStream output) throws IOException {
+ super(output, new ProcessingInstruction[] {ProcessingInstruction.makeTargetVersionInstruction(PROFILE_TARGET, ProfileXMLConstants.CURRENT_VERSION)});
+ }
}
private void setRunnableProperty(IArtifactRepository destinationArtifactRepository) {
@@ -261,9 +354,10 @@ public class Repo2Runnable extends AbstractApplication implements IApplication {
return;
for (int i = 0; i < args.length; i++) {
String option = args[i];
- if (i == args.length - 1 || args[i + 1].startsWith("-")) //$NON-NLS-1$
- continue;
- String arg = args[++i];
+ String arg = null;
+ if (i != args.length - 1 && !args[i + 1].startsWith("-")) { //$NON-NLS-1$
+ arg = args[++i];
+ }
if (option.equalsIgnoreCase("-source")) { //$NON-NLS-1$
RepositoryDescriptor source = new RepositoryDescriptor();
@@ -280,6 +374,10 @@ public class Repo2Runnable extends AbstractApplication implements IApplication {
if (option.equalsIgnoreCase("-flagAsRunnable")) { //$NON-NLS-1$
setFlagAsRunnable(true);
}
+
+ if (option.equalsIgnoreCase("-createFragments")) { //$NON-NLS-1$
+ setCreateFragments(true);
+ }
}
}
@@ -306,4 +404,9 @@ public class Repo2Runnable extends AbstractApplication implements IApplication {
public void stop() {
// nothing to do
}
+
+ public void setCreateFragments(boolean createFragments) {
+ this.createFragments = createFragments;
+
+ }
}
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 aef9767a3..d46c9759b 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
@@ -48,6 +48,7 @@ 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.
+Repo2Runnable_12=Couldn't find bundle file or directory for {0}_{1}
Repo2RunnableTask_errorTransforming=Error occurred while transforming repository: {0}.
message_mirroringStatus = Messages while mirroring artifact descriptors.
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 f782f626b..492d99ee6 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 IBM Corporation and others.
+ * Copyright (c) 2009, 2013 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Red Hat, Inc. - fragment creation
*******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
@@ -33,6 +34,7 @@ public class Repo2RunnableTask extends AbstractRepositoryTask {
private boolean failOnError = true;
private boolean flagAsRunnable = false;
+ private boolean createFragments = false;
/*
* Constructor for the class. Create a new instance of the application
@@ -55,6 +57,7 @@ public class Repo2RunnableTask extends AbstractRepositoryTask {
throw new BuildException(Messages.exception_needIUsOrNonEmptyRepo);
application.setSourceIUs(ius);
((Repo2Runnable) application).setFlagAsRunnable(flagAsRunnable);
+ ((Repo2Runnable) application).setCreateFragments(createFragments);
IStatus result = application.run(null);
if (failOnError && result.matches(IStatus.ERROR))
throw new ProvisionException(result);
@@ -74,4 +77,8 @@ public class Repo2RunnableTask extends AbstractRepositoryTask {
public void setFlagAsRunnable(boolean runnable) {
this.flagAsRunnable = runnable;
}
+
+ public void setCreateFragments(boolean fragments) {
+ this.createFragments = fragments;
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/Repo2RunnableTaskTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/Repo2RunnableTaskTests.java
index 1bc399980..f84d2418f 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/Repo2RunnableTaskTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/Repo2RunnableTaskTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 IBM Corporation and others.
+ * Copyright (c) 2009, 2013 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
@@ -7,10 +7,11 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Red Hat, Inc. - fragments support added.
*******************************************************************************/
package org.eclipse.equinox.p2.tests.ant;
-import java.io.File;
+import java.io.*;
import java.net.URI;
import java.util.Iterator;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -53,6 +54,25 @@ public class Repo2RunnableTaskTests extends AbstractAntProvisioningTest {
assertTrue("Unexpected format", expectedFormat(destination));
}
+ public void testRepo2RunnableFragments() throws IOException {
+ createRepo2RunnableTaskElementFragments(TYPE_BOTH);
+
+ runAntTask();
+ assertEquals("Number of artifact keys differs", getArtifactKeyCount(source), getArtifactKeyCount(destination));
+ assertTrue("Unexpected format", expectedFormat(destination));
+ File f = new File(destination);
+ assertTrue("Missing content.jar", new File(f, "content.jar").exists());
+ assertTrue("Missing artifacts.jar", new File(f, "artifacts.jar").exists());
+ assertTrue("Missing artifacts.jar", new File(f, "fragment.profile").exists());
+ assertTrue("Missing artifacts.jar", new File(f, "fragment.info").exists());
+ BufferedReader br = new BufferedReader(new FileReader(new File(f, "fragment.profile")));
+ while (br.ready())
+ System.out.println(br.readLine());
+ br = new BufferedReader(new FileReader(new File(f, "fragment.info")));
+ while (br.ready())
+ System.out.println(br.readLine());
+ }
+
/*
* Test that when an IU is specified that it is used
*/
@@ -157,4 +177,20 @@ public class Repo2RunnableTaskTests extends AbstractAntProvisioningTest {
return task;
}
+
+ protected AntTaskElement createRepo2RunnableTaskElementFragments(String type) {
+ AntTaskElement task = createRepo2RunnableTaskElement();
+ task.addElement(getRepositoryElement(destination, type));
+
+ AntTaskElement sourceElement = new AntTaskElement("source");
+ sourceElement.addElement(getRepositoryElement(source, type));
+ task.addElement(sourceElement);
+
+ // AntTaskElement fragmentsElement = new AntTaskElement("createFragments");
+ // fragmentsElement.a
+ // task.addElement(fragmentsElement);
+
+ task.addAttribute("createFragments", "true");
+ return task;
+ }
}

Back to the top