From 98a2643f44af0ac0659f6a15a8f242ff04251286 Mon Sep 17 00:00:00 2001 From: Lars Fritsche Date: Wed, 9 Feb 2022 17:41:08 +0100 Subject: [PATCH] implemented a nature, builder and iapplication to create updatesites --- org.emoflon.site.build/.classpath | 7 ++ org.emoflon.site.build/.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 9 ++ org.emoflon.site.build/META-INF/MANIFEST.MF | 14 +++ org.emoflon.site.build/bin/.gitignore | 1 + org.emoflon.site.build/build.properties | 11 ++ org.emoflon.site.build/plugin.xml | 42 ++++++++ .../emoflon/sitexml/MoflonSiteXMLNature.java | 32 ++++++ .../org/emoflon/sitexml/SiteXMLBuilder.java | 52 +++++++++ .../emoflon/sitexml/SiteXMLBuilderApp.java | 100 +++++++++++++++++ org.emoflon.site.feature/.project | 17 +++ org.emoflon.site.feature/build.properties | 1 + org.emoflon.site.feature/feature.xml | 87 +++++++++++++++ org.emoflon.site.updatesite/.project | 17 +++ .../AntUtilitiesBuild.xml | 102 ++++++++++++++++++ .../launch/ant clean (emoflon-ibex).launch | 15 +++ .../ant createArchive (emoflon-ibex).launch | 16 +++ org.emoflon.site.updatesite/site.xml | 7 ++ 18 files changed, 558 insertions(+) create mode 100644 org.emoflon.site.build/.classpath create mode 100644 org.emoflon.site.build/.project create mode 100644 org.emoflon.site.build/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.emoflon.site.build/META-INF/MANIFEST.MF create mode 100644 org.emoflon.site.build/bin/.gitignore create mode 100644 org.emoflon.site.build/build.properties create mode 100644 org.emoflon.site.build/plugin.xml create mode 100644 org.emoflon.site.build/src/org/emoflon/sitexml/MoflonSiteXMLNature.java create mode 100644 org.emoflon.site.build/src/org/emoflon/sitexml/SiteXMLBuilder.java create mode 100644 org.emoflon.site.build/src/org/emoflon/sitexml/SiteXMLBuilderApp.java create mode 100644 org.emoflon.site.feature/.project create mode 100644 org.emoflon.site.feature/build.properties create mode 100644 org.emoflon.site.feature/feature.xml create mode 100644 org.emoflon.site.updatesite/.project create mode 100644 org.emoflon.site.updatesite/AntUtilitiesBuild.xml create mode 100644 org.emoflon.site.updatesite/launch/ant clean (emoflon-ibex).launch create mode 100644 org.emoflon.site.updatesite/launch/ant createArchive (emoflon-ibex).launch create mode 100644 org.emoflon.site.updatesite/site.xml diff --git a/org.emoflon.site.build/.classpath b/org.emoflon.site.build/.classpath new file mode 100644 index 0000000..4d23c29 --- /dev/null +++ b/org.emoflon.site.build/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.emoflon.site.build/.project b/org.emoflon.site.build/.project new file mode 100644 index 0000000..59fabef --- /dev/null +++ b/org.emoflon.site.build/.project @@ -0,0 +1,28 @@ + + + org.emoflon.site.build + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/org.emoflon.site.build/.settings/org.eclipse.jdt.core.prefs b/org.emoflon.site.build/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..a408b60 --- /dev/null +++ b/org.emoflon.site.build/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 +org.eclipse.jdt.core.compiler.compliance=16 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=16 diff --git a/org.emoflon.site.build/META-INF/MANIFEST.MF b/org.emoflon.site.build/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3965f18 --- /dev/null +++ b/org.emoflon.site.build/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: SiteXMLBuilder +Bundle-SymbolicName: org.emoflon.site.build;singleton:=true +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.core.resources, + org.eclipse.pde.core;visibility:=reexport, + org.eclipse.ant.core;visibility:=reexport, + org.apache.ant, + org.eclipse.debug.core, + org.eclipse.equinox.launcher;bundle-version="1.6.400" +Export-Package: org.emoflon.sitexml +Bundle-ActivationPolicy: lazy diff --git a/org.emoflon.site.build/bin/.gitignore b/org.emoflon.site.build/bin/.gitignore new file mode 100644 index 0000000..cf1db2e --- /dev/null +++ b/org.emoflon.site.build/bin/.gitignore @@ -0,0 +1 @@ +/org/ diff --git a/org.emoflon.site.build/build.properties b/org.emoflon.site.build/build.properties new file mode 100644 index 0000000..863d67a --- /dev/null +++ b/org.emoflon.site.build/build.properties @@ -0,0 +1,11 @@ +bin.includes = META-INF/,\ + build.properties,\ + plugin.xml,\ + src/,\ + model/,\ + .project,\ + .classpath,\ + bin/ +jars.compile.order = . +source.. = src/ +output.. = bin/ diff --git a/org.emoflon.site.build/plugin.xml b/org.emoflon.site.build/plugin.xml new file mode 100644 index 0000000..731c0b7 --- /dev/null +++ b/org.emoflon.site.build/plugin.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.emoflon.site.build/src/org/emoflon/sitexml/MoflonSiteXMLNature.java b/org.emoflon.site.build/src/org/emoflon/sitexml/MoflonSiteXMLNature.java new file mode 100644 index 0000000..5ea9b93 --- /dev/null +++ b/org.emoflon.site.build/src/org/emoflon/sitexml/MoflonSiteXMLNature.java @@ -0,0 +1,32 @@ +package org.emoflon.sitexml; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; + +public class MoflonSiteXMLNature implements IProjectNature { + private IProject project; + + @Override + public void configure() throws CoreException { + // TODO Auto-generated method stub + + } + + @Override + public void deconfigure() throws CoreException { + // TODO Auto-generated method stub + + } + + @Override + public IProject getProject() { + return project; + } + + @Override + public void setProject(IProject project) { + this.project = project; + } + +} diff --git a/org.emoflon.site.build/src/org/emoflon/sitexml/SiteXMLBuilder.java b/org.emoflon.site.build/src/org/emoflon/sitexml/SiteXMLBuilder.java new file mode 100644 index 0000000..e2b5578 --- /dev/null +++ b/org.emoflon.site.build/src/org/emoflon/sitexml/SiteXMLBuilder.java @@ -0,0 +1,52 @@ +package org.emoflon.sitexml; + +import java.util.ArrayList; +import java.util.Map; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.pde.internal.core.PDECore; +import org.eclipse.pde.internal.core.exports.SiteBuildOperation; +import org.eclipse.pde.internal.core.ifeature.IFeatureModel; +import org.eclipse.pde.internal.core.isite.ISiteFeature; +import org.eclipse.pde.internal.core.isite.ISiteModel; +import org.eclipse.pde.internal.core.site.WorkspaceSiteModel; + +public class SiteXMLBuilder extends IncrementalProjectBuilder { + + private static final String SITEXML_ID = "org.moflon.emf.build.SiteXMLBuilder"; + + @Override + protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { + if(kind != FULL_BUILD) { + return null; + } + IFile siteFile = getProject().getFile("site.xml"); + ISiteModel buildSiteModel = new WorkspaceSiteModel(siteFile); + buildSiteModel.load(); + System.out.println(); + ISiteFeature[] features = buildSiteModel.getSite().getFeatures(); + IFeatureModel[] featureModels = getFeatureModels(features); + + Job job = new SiteBuildOperation(featureModels, buildSiteModel, ""); + job.setUser(true); + job.schedule(); + return null; + } + + + private IFeatureModel[] getFeatureModels(ISiteFeature[] sFeatures) { + ArrayList list = new ArrayList<>(); + for (ISiteFeature siteFeature : sFeatures) { + IFeatureModel model = PDECore.getDefault().getFeatureModelManager().findFeatureModelRelaxed(siteFeature.getId(), siteFeature.getVersion()); + if (model != null) + list.add(model); + } + return list.toArray(new IFeatureModel[list.size()]); + } + +} diff --git a/org.emoflon.site.build/src/org/emoflon/sitexml/SiteXMLBuilderApp.java b/org.emoflon.site.build/src/org/emoflon/sitexml/SiteXMLBuilderApp.java new file mode 100644 index 0000000..b8cb8ac --- /dev/null +++ b/org.emoflon.site.build/src/org/emoflon/sitexml/SiteXMLBuilderApp.java @@ -0,0 +1,100 @@ +package org.emoflon.sitexml; + +import java.util.ArrayList; +import java.util.Map; + +import org.eclipse.ant.core.AntCorePlugin; +import org.eclipse.ant.internal.core.AntClassLoader; +import org.eclipse.core.internal.jobs.InternalJob; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.app.IApplicationContext; +import org.eclipse.osgi.internal.framework.EquinoxBundle; +import org.eclipse.osgi.internal.framework.EquinoxContainer; +import org.eclipse.osgi.internal.loader.EquinoxClassLoader; +import org.eclipse.osgi.internal.url.EquinoxFactoryManager; +import org.eclipse.osgi.launch.Equinox; +import org.eclipse.pde.internal.core.PDECore; +import org.eclipse.pde.internal.core.exports.SiteBuildOperation; +import org.eclipse.pde.internal.core.ifeature.IFeatureModel; +import org.eclipse.pde.internal.core.isite.ISiteFeature; +import org.eclipse.pde.internal.core.isite.ISiteModel; +import org.eclipse.pde.internal.core.site.WorkspaceSiteModel; + +public class SiteXMLBuilderApp implements IApplication { + + @Override + public Object start(IApplicationContext context) throws Exception { + String[] arguments = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS); + String projectName = getProject(arguments); + + if(projectName == null) { + throw new RuntimeException("No project was specified!\n Entries: " + arguments); + } + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IProject project = workspace.getRoot().getProject(projectName); + if(project == null) + throw new RuntimeException("Project " + projectName + " not found!"); + + AntClassLoader.getSystemClassLoader(); + AntClassLoader.getPlatformClassLoader(); + AntCorePlugin.getPlugin(); + + IFile siteFile = project.getFile("site.xml"); + ISiteModel buildSiteModel = new WorkspaceSiteModel(siteFile); + buildSiteModel.load(); + System.out.println(); + ISiteFeature[] features = buildSiteModel.getSite().getFeatures(); + IFeatureModel[] featureModels = getFeatureModels(features); + + try { + SiteBuildOperation job = new SiteBuildOperation(featureModels, buildSiteModel, ""); + job.setUser(true); + job.schedule(); + job.join(); + } + catch(Exception e) { + + } + + return null; + } + + private String getProject(String[] arguments) { + for(int i=0; i < arguments.length; i++) { + if(arguments[i].equals("-project")) { + if(i+1 >= arguments.length) { + throw new RuntimeException("No project was specified!"); + } + else { + return arguments[i+1]; + } + } + } + return null; + } + + private IFeatureModel[] getFeatureModels(ISiteFeature[] sFeatures) { + ArrayList list = new ArrayList<>(); + for (ISiteFeature siteFeature : sFeatures) { + IFeatureModel model = PDECore.getDefault().getFeatureModelManager().findFeatureModelRelaxed(siteFeature.getId(), siteFeature.getVersion()); + if (model != null) + list.add(model); + } + return list.toArray(new IFeatureModel[list.size()]); + } + + @Override + public void stop() { + + } + +} diff --git a/org.emoflon.site.feature/.project b/org.emoflon.site.feature/.project new file mode 100644 index 0000000..38972b5 --- /dev/null +++ b/org.emoflon.site.feature/.project @@ -0,0 +1,17 @@ + + + org.emoflon.site.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/org.emoflon.site.feature/build.properties b/org.emoflon.site.feature/build.properties new file mode 100644 index 0000000..64f93a9 --- /dev/null +++ b/org.emoflon.site.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/org.emoflon.site.feature/feature.xml b/org.emoflon.site.feature/feature.xml new file mode 100644 index 0000000..1c5fbe5 --- /dev/null +++ b/org.emoflon.site.feature/feature.xml @@ -0,0 +1,87 @@ + + + + + [Enter Feature Description here.] + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.emoflon.site.updatesite/.project b/org.emoflon.site.updatesite/.project new file mode 100644 index 0000000..a989c30 --- /dev/null +++ b/org.emoflon.site.updatesite/.project @@ -0,0 +1,17 @@ + + + org.emoflon.site.updatesite + + + + + + org.eclipse.pde.UpdateSiteBuilder + + + + + + org.eclipse.pde.UpdateSiteNature + + diff --git a/org.emoflon.site.updatesite/AntUtilitiesBuild.xml b/org.emoflon.site.updatesite/AntUtilitiesBuild.xml new file mode 100644 index 0000000..aabf5af --- /dev/null +++ b/org.emoflon.site.updatesite/AntUtilitiesBuild.xml @@ -0,0 +1,102 @@ + + + Helper ant file for the update site of eMoflon. + + **NOTE:** It is important that the script runs in the same JRE as the surrounding workspace to allow executing + 'eclipse.*' tasks + See "External Tools Configurations..." -> [Run Config] -> JRE -> "Run in the same JRE as workspace" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.emoflon.site.updatesite/launch/ant clean (emoflon-ibex).launch b/org.emoflon.site.updatesite/launch/ant clean (emoflon-ibex).launch new file mode 100644 index 0000000..9a9cf88 --- /dev/null +++ b/org.emoflon.site.updatesite/launch/ant clean (emoflon-ibex).launch @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/org.emoflon.site.updatesite/launch/ant createArchive (emoflon-ibex).launch b/org.emoflon.site.updatesite/launch/ant createArchive (emoflon-ibex).launch new file mode 100644 index 0000000..a88e5d9 --- /dev/null +++ b/org.emoflon.site.updatesite/launch/ant createArchive (emoflon-ibex).launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/org.emoflon.site.updatesite/site.xml b/org.emoflon.site.updatesite/site.xml new file mode 100644 index 0000000..e8f3dac --- /dev/null +++ b/org.emoflon.site.updatesite/site.xml @@ -0,0 +1,7 @@ + + + + + + +