Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'rpmstubby')
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF4
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfileWriter.java71
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java173
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyPackageModel.java384
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/FeatureModel.java165
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/IPackage.java45
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/IPackagePreamble.java45
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/MainPackage.java149
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/PackageItem.java51
-rw-r--r--rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/SubPackage.java105
10 files changed, 267 insertions, 925 deletions
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF b/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF
index 86a5ec2aea..86278afd99 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF
@@ -9,9 +9,7 @@ Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
- org.eclipse.ui.ide,
- org.eclipse.update.core
-Eclipse-LazyStart: true
+ org.eclipse.ui.ide
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.linuxtools.rpmstubby
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfileWriter.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfileWriter.java
index 255238601d..617d78db28 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfileWriter.java
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/SpecfileWriter.java
@@ -10,15 +10,8 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.rpmstubby;
-import java.util.ArrayList;
-import java.util.List;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.linuxtools.internal.rpmstubby.model.MainPackage;
-import org.eclipse.linuxtools.internal.rpmstubby.model.SubPackage;
/**
* Utility class used for writing the generated specfile to a file.
@@ -26,69 +19,17 @@ import org.eclipse.linuxtools.internal.rpmstubby.model.SubPackage;
*/
public class SpecfileWriter {
- IPreferenceStore store;
-
- /**
- * Creates the writer.
- */
- public SpecfileWriter() {
- store = StubbyPlugin.getDefault().getPreferenceStore();
- }
-
/**
* Parse the feature.xml and write the generated specfile.
* @param featureFile The feature.xml file.
*/
public void write(IFile featureFile) {
- // Populate Main package model
- StubbyPackageModel stubbyPackageModel = new StubbyPackageModel(
- featureFile);
- MainPackage mainPackage = new MainPackage();
- stubbyPackageModel.populatePackageData(mainPackage);
- stubbyPackageModel.populatePackagePreambleData(mainPackage);
- stubbyPackageModel.populateDocFiles(mainPackage);
- List<IFile> includedFeatureFiles = stubbyPackageModel.getIncudedFeatures();
- // Populate Sub package model
- List<SubPackage> subPackages = new ArrayList<SubPackage>();
- for (IFile includedFeatureFile: includedFeatureFiles) {
- StubbyPackageModel strubbySubPackageModel = new StubbyPackageModel(
- includedFeatureFile);
- SubPackage subPackage = new SubPackage();
- strubbySubPackageModel.populatePackageData(subPackage);
- subPackages.add(subPackage);
- }
- if (!stubbyPackageModel.isAllIncludedFeatureFound()) {
- String message = "";
- if (stubbyPackageModel.getMissingFeaturesAsString().indexOf(",") >= 0) {
- message = "Stub out an RPM specfile for '"
- + mainPackage.getName()
- + "' fails because '"
- + stubbyPackageModel.getMissingFeaturesAsString()
- + "' features were not found.\n\n"
- + "Please, add these features somewhere in your workspace.\n";
- } else {
- message = "Stub out an RPM specfile for '"
- + mainPackage.getName()
- + "' fails because '"
- + stubbyPackageModel.getMissingFeaturesAsString()
- + "' feature was not found.\n\n"
- + "Please, add these feature somewhere in your workspace.\n";
- }
- MessageDialog.openError(StubbyPlugin.getActiveWorkbenchShell(),
- null, message);
- } else {
- // Write generated files to the main feature project
- StubbyGenerator generator = new StubbyGenerator(mainPackage,
- subPackages);
- String packageName = "eclipse-"
- + generator.getPackageName(mainPackage.getName());
- try {
- generator.writeContent(featureFile.getProject().getName(), packageName.toLowerCase() + ".spec", generator.generateSpecfile());
- } catch (CoreException e) {
- StubbyLog.logError(e);
- }
- }
+ StubbyGenerator generator = new StubbyGenerator(featureFile);
+ try {
+ generator.writeContent(featureFile.getProject().getName());
+ } catch (CoreException e) {
+ StubbyLog.logError(e);
+ }
}
-
}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java
index 90504a44be..e5dcc5bfc4 100644
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyGenerator.java
@@ -11,9 +11,15 @@
package org.eclipse.linuxtools.internal.rpmstubby;
import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.util.List;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@@ -21,16 +27,17 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
-import org.eclipse.linuxtools.internal.rpmstubby.model.MainPackage;
-import org.eclipse.linuxtools.internal.rpmstubby.model.PackageItem;
-import org.eclipse.linuxtools.internal.rpmstubby.model.SubPackage;
+import org.eclipse.linuxtools.internal.rpmstubby.model.FeatureModel;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
/**
* Generates the RPM specfile and the fetch script based on the feature and user
@@ -39,90 +46,107 @@ import org.eclipse.ui.ide.IDE;
*/
public class StubbyGenerator {
- private MainPackage mainPackage;
- private List<SubPackage> subPackages;
+ private FeatureModel model;
+ private IFile featureFile;
/**
* Creates the specfile and fetch script generator for the given packages.
*
- * @param mainPackage
- * The main feature.
- * @param subPackages
- * The included features or plugins.
+ * @param featureFile
+ * The feature.xml file to generate from.
*/
- public StubbyGenerator(MainPackage mainPackage, List<SubPackage> subPackages) {
- this.mainPackage = mainPackage;
- this.subPackages = subPackages;
+ public StubbyGenerator(IFile featureFile) {
+ this.featureFile = featureFile;
+ parse(featureFile);
+ }
+
+ private void parse(IFile featureFile) {
+ DocumentBuilderFactory docfactory = DocumentBuilderFactory
+ .newInstance();
+ IPath featureDir = featureFile.getLocation().removeLastSegments(1);
+ String featurePropertiesFile = featureDir.toOSString()
+ + "/feature.properties";
+ Properties featureProperties = new Properties();
+ try {
+ featureProperties.load(new FileInputStream(featurePropertiesFile));
+ } catch (FileNotFoundException e) {
+ // Do nothing if the feature.properties is not found
+ } catch (IOException e) {
+ StubbyLog.logError(e);
+ }
+ DocumentBuilder docbuilder;
+ try {
+ docbuilder = docfactory.newDocumentBuilder();
+ Document docroot = docbuilder.parse(featureFile.getContents());
+ model = new FeatureModel(docroot, featureProperties);
+
+ } catch (ParserConfigurationException e) {
+ StubbyLog.logError(e);
+ } catch (SAXException e) {
+ StubbyLog.logError(e);
+ } catch (IOException e) {
+ StubbyLog.logError(e);
+ } catch (CoreException e) {
+ StubbyLog.logError(e);
+ }
}
/**
- * Generates a RPM specfile based on the parsed data from the feature.xml.
+ * Generates a RPM specfile based on the parsed data from the pom file.
*
* @return The generated specfile.
*/
public String generateSpecfile() {
StringBuilder buffer = new StringBuilder();
- String simplePackageName = getPackageName(mainPackage.getName());
- String packageName = "eclipse-" + simplePackageName;
buffer.append("%global eclipse_base %{_libdir}/eclipse\n");
buffer.append("%global install_loc %{_datadir}/eclipse/dropins/"
- + simplePackageName.toLowerCase() + "\n\n");
- buffer.append("Name: " + packageName.toLowerCase() + "\n");
- buffer.append("Version: "
- + mainPackage.getVersion().replaceAll("\\.qualifier", "")
- + "\n");
+ + model.getSimplePackageName() + "\n\n");
+ buffer.append("Name: " + model.getPackageName().toLowerCase() + "\n");
+ buffer.append("Version: " + model.getVersion() + "\n");
buffer.append("Release: 1%{?dist}" + "\n");
- buffer.append("Summary: " + mainPackage.getSummary() + "\n\n");
+ buffer.append("Summary: " + model.getSummary() + "\n\n");
buffer.append("Group: Development/Tools\n");
- buffer.append("License: " + mainPackage.getLicense() + "\n");
- buffer.append("URL: " + mainPackage.getURL() + "\n");
+ buffer.append("License: " + model.getLicense() + "\n");
+ buffer.append("URL: " + model.getURL() + "\n");
buffer.append("Source0: #FIXME\n");
buffer.append("BuildArch: noarch\n\n");
+ generateRequires(buffer);
+ buffer.append("\n%description\n" + model.getDescription() + "\n");
+ generatePrepSection(buffer);
+ generateBuildSection(buffer);
+ generateInstallSection(buffer);
+ generateFilesSections(buffer);
+ generateChangelog(buffer);
+
+ return buffer.toString();
+ }
+
+ private void generateRequires(StringBuilder buffer) {
buffer.append("BuildRequires: eclipse-pde >= 1:3.4.0\n");
buffer.append("Requires: eclipse-platform >= 3.4.0\n");
- buffer.append("\n%description\n" + mainPackage.getDescription() + "\n");
- for (SubPackage subPackage : subPackages) {
- String subPackageName = getPackageName(subPackage.getName());
- buffer.append("\n%package " + subPackageName + "\n");
- buffer.append("Summary: " + subPackage.getSummary() + "\n");
- buffer.append("Requires: %{name} = %{version}-%{release}\n");
- buffer.append("Group: Development/Tools\n\n");
- buffer.append("%description " + subPackageName + "\n");
- buffer.append(subPackage.getDescription() + "\n");
- }
- generatePrepSection(buffer);
- generateBuildSection(buffer);
+ }
+
+ private void generateInstallSection(StringBuilder buffer) {
buffer.append("%install\n");
buffer.append("install -d -m 755 %{buildroot}%{install_loc}\n\n");
buffer.append("%{__unzip} -q -d %{buildroot}%{install_loc} \\\n");
- buffer.append(" build/rpmBuild/" + mainPackage.getName()
+ buffer.append(" build/rpmBuild/" + model.getFeatureId()
+ ".zip \n\n");
- generateFilesSections(buffer);
- buffer.append("%changelog\n\n");
- buffer.append("#FIXME\n");
- return buffer.toString();
+
}
private void generateFilesSections(StringBuilder buffer) {
buffer.append("%files\n");
buffer.append("%{install_loc}\n");
- for (String fileName : mainPackage.getDocFiles()) {
- buffer.append("%doc ").append(mainPackage.getDocFilesRoot())
- .append("/").append(fileName).append("\n");
+ String docsRoot = featureFile.getLocation().removeLastSegments(1).lastSegment();
+ String[] files = featureFile.getLocation().removeLastSegments(1).toFile().list();
+ for (String file :files){
+ if (file.matches("(epl-.*|license)\\.html")){
+ buffer.append("%doc "+docsRoot+"/"+file+"\n");
+ }
}
buffer.append("\n");
- for (SubPackage subPackage : subPackages) {
- buffer.append("%files " + getPackageName(subPackage.getName())
- + "\n");
- buffer.append("%dir %{eclipse_base}/features/"
- + subPackage.getName() + "_*/\n");
- buffer.append("%doc %{eclipse_base}/features/"
- + subPackage.getName() + "_*/*.html\n");
- buffer.append("%{eclipse_base}/features/" + subPackage.getName()
- + "_*/feature.*\n");
- buffer.append(getPackageFiles(subPackage.getProvides()) + "\n");
- }
}
private void generatePrepSection(StringBuilder buffer) {
@@ -134,7 +158,7 @@ public class StubbyGenerator {
private void generateBuildSection(StringBuilder buffer) {
buffer.append("%build\n");
buffer.append("%{eclipse_base}/buildscripts/pdebuild -f ").append(
- mainPackage.getName());
+ model.getFeatureId());
buffer.append("\n\n");
}
@@ -152,7 +176,18 @@ public class StubbyGenerator {
if (name.equalsIgnoreCase("feature")) {
name = packageItems[packageItems.length - 2];
}
- return name;
+ return "eclipse-" + name;
+ }
+
+ private void throwCoreException(String message) throws CoreException {
+ IStatus status = new Status(IStatus.ERROR, StubbyPlugin.PLUGIN_ID,
+ IStatus.OK, message, null);
+ throw new CoreException(status);
+ }
+
+ private void generateChangelog(StringBuilder buffer) {
+ buffer.append("%changelog\n\n");
+ buffer.append("#FIXME\n");
}
/**
@@ -161,15 +196,12 @@ public class StubbyGenerator {
*
* @param projectName
* The name of the project to put the file into.
- * @param fileName
- * The name of the file.
- * @param contents
- * The contents of the file.
* @throws CoreException
* Thrown when the project doesn't exist.
*/
- public void writeContent(String projectName, String fileName,
- String contents) throws CoreException {
+ public void writeContent(String projectName) throws CoreException {
+ String fileName = model.getPackageName().toLowerCase() + ".spec";
+ String contents = generateSpecfile();
InputStream contentInputStream = new ByteArrayInputStream(
contents.getBytes());
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
@@ -204,19 +236,4 @@ public class StubbyGenerator {
}
});
}
-
- private void throwCoreException(String message) throws CoreException {
- IStatus status = new Status(IStatus.ERROR, StubbyPlugin.PLUGIN_ID,
- IStatus.OK, message, null);
- throw new CoreException(status);
- }
-
- private String getPackageFiles(List<PackageItem> packageItems) {
- StringBuilder toRet = new StringBuilder();
- for (PackageItem packageItem : packageItems) {
- toRet.append("%{eclipse_base}/plugins/")
- .append(packageItem.getName()).append("_*.jar\n");
- }
- return toRet.toString();
- }
}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyPackageModel.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyPackageModel.java
deleted file mode 100644
index 9628e3e8fb..0000000000
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/StubbyPackageModel.java
+++ /dev/null
@@ -1,384 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Alphonse Van Assche.
- * 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:
- * Alphonse Van Assche - initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.rpmstubby;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.linuxtools.internal.rpmstubby.model.IPackage;
-import org.eclipse.linuxtools.internal.rpmstubby.model.IPackagePreamble;
-import org.eclipse.linuxtools.internal.rpmstubby.model.MainPackage;
-import org.eclipse.linuxtools.internal.rpmstubby.model.PackageItem;
-import org.eclipse.update.core.IIncludedFeatureReference;
-import org.eclipse.update.core.VersionedIdentifier;
-import org.eclipse.update.core.model.FeatureModel;
-import org.eclipse.update.core.model.FeatureModelFactory;
-import org.eclipse.update.core.model.ImportModel;
-import org.eclipse.update.core.model.PluginEntryModel;
-import org.eclipse.update.core.model.URLEntryModel;
-import org.xml.sax.SAXException;
-
-/**
- * Internal representation of the package model.
- *
- */
-public class StubbyPackageModel {
-
- private static final String VALUE_NOT_FOUND = "#FIXME";
- private String featurePropertiesFile;
- private IPath featureDir;
- private FeatureModel featureModel;
- private List<IFile> includedFeatureFiles = new ArrayList<IFile>();
- private List<String> includedFeatureIdentifiers;
- private List<String> includedFeatureIdentifiersAdded;
-
- /**
- * Creates the package model from the given feature file.
- * @param featureFile The feature.xml file to use.
- */
- public StubbyPackageModel(IFile featureFile) {
- this.featureDir = featureFile.getLocation().removeLastSegments(1);
- this.featurePropertiesFile = featureDir.toOSString()+ "/feature.properties";
- FeatureModelFactory featureModelFactory = new FeatureModelFactory();
- try {
- this.featureModel = featureModelFactory.parseFeature(featureFile
- .getContents());
- } catch (CoreException e) {
- // Can be throw if the file does not exist.
- StubbyLog.logError(e);
- } catch (SAXException e) {
- // Probably malformed feature.xml?
- StubbyLog.logError(e);
- }
- }
-
- /**
- * Fills the doc files in the package model.
- * @param packageModel The package model to fill.
- */
- public void populateDocFiles(MainPackage packageModel) {
- String[] files = featureDir.toFile().list();
- List<String> docFiles = new ArrayList<String>();
- for (String file :files){
- if (file.matches("(epl-.*|license)\\.html")){
- docFiles.add(file);
- }
- }
- packageModel.setDocFiles(docFiles);
- packageModel.setDocFilesRoot(featureDir.lastSegment());
- }
-
- /**
- * Fills the package model from the parsed data from the feature.xml file.
- * @param packageModel The package model to fill.
- */
- public void populatePackageData(IPackage packageModel) {
- packageModel.setName(getFeatureName());
- packageModel.setVersion(getVersion());
- packageModel.setSummary(getSummary());
- packageModel.setDescription(getDescription());
- packageModel.setProvides(getProvides());
- packageModel.setRequires(getRequires());
- }
-
- /**
- * Fills the package preamble data.
- * @param packagePreambleModel The container to fill.
- */
- public void populatePackagePreambleData(
- IPackagePreamble packagePreambleModel) {
- packagePreambleModel.setURL(getURL());
- packagePreambleModel.setLicense(getLicense());
- }
-
- /**
- * Returns the list of all feature.xml files imported in the root feature.
- * @return The list of all feature.xml files.
- */
- public List<IFile> getIncudedFeatures() {
- FeatureModelFactory featureModelFactory = new FeatureModelFactory();
- IIncludedFeatureReference[] includedFeatureReferences = featureModel
- .getFeatureIncluded();
- includedFeatureIdentifiers = new ArrayList<String>();
- includedFeatureIdentifiersAdded = new ArrayList<String>();
- try {
- for (IIncludedFeatureReference includedFeatureReference: includedFeatureReferences) {
- VersionedIdentifier versionedIdentifier = includedFeatureReference.getVersionedIdentifier();
- includedFeatureIdentifiers.add(versionedIdentifier
- .getIdentifier());
- }
- IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
- IProject[] projects = workspace.getProjects();
- for (IProject project: projects) {
- FeatureVisitor featureVisitor = new FeatureVisitor();
- project.accept(featureVisitor);
- for (IFile featureFile : featureVisitor.getFeatures()) {
- FeatureModel includedFeatureModel = featureModelFactory
- .parseFeature(featureFile.getContents());
- if (isFeatureIncluded(includedFeatureModel
- .getFeatureIdentifier())) {
- // Each feature that include other features is
- // considered as a
- // top-level RPM package.
- if (includedFeatureModel.getFeatureIncluded().length > 0) {
- SpecfileWriter specfileWriter = new SpecfileWriter();
- specfileWriter.write(featureFile);
- } else
- includedFeatureIdentifiersAdded
- .add(includedFeatureModel
- .getFeatureIdentifier());
- includedFeatureFiles.add(featureFile);
- }
- }
- }
- } catch (CoreException e) {
- StubbyLog.logError(e);
- } catch (SAXException e) {
- StubbyLog.logError(e);
- }
- return includedFeatureFiles;
- }
-
- /**
- * Checks whether all the features are included.
- * @return True if all are included, false otherwise.
- */
- public boolean isAllIncludedFeatureFound() {
- if (includedFeatureFiles.size() == includedFeatureIdentifiers.size())
- return true;
- else
- return false;
- }
-
- /**
- * Returns string representation of all the missing features.
- * @return The missing features separated by ,
- */
- public String getMissingFeaturesAsString() {
- String toRet = "";
- for (String includedFeatureIdentifier: includedFeatureIdentifiers) {
- if (!includedFeatureIdentifiersAdded
- .contains(includedFeatureIdentifier))
- ;
- toRet += includedFeatureIdentifier + ", ";
- }
- return toRet.substring(0, toRet.length() - 2);
- }
-
- private boolean isFeatureIncluded(String featureIdetifier) {
- for (String includedFeatureIdentifier: includedFeatureIdentifiers) {
- // Check if the feature found by the visitor is a included feature
- if (includedFeatureIdentifier.equals(featureIdetifier)) {
- // Check if the given feature is not already added in the
- // included feature list.
- for (String includedFeatureID : includedFeatureIdentifiersAdded) {
- if (includedFeatureID.equals(featureIdetifier)) {
- return false;
- }
- }
- return true;
- }
- }
- return false;
- }
-
- private String getFeatureName() {
- return featureModel.getFeatureIdentifier();
- }
-
- private String getVersion() {
- return featureModel.getFeatureVersion();
- }
-
- private String getSummary() {
- return resolveFeatureProperties(featureModel.getLabel());
- }
-
- private String getLicense() {
- String license = VALUE_NOT_FOUND;
- URLEntryModel licenseModel = featureModel.getLicenseModel();
- if (licenseModel != null) {
- String urlString = resolveFeatureProperties(licenseModel
- .getURLString());
- String urlAnotation = resolveFeatureProperties(licenseModel
- .getAnnotation());
- if ((urlString != null && urlAnotation != null)) {
- if ((urlString.indexOf("epl") > -1 || urlAnotation
- .indexOf("epl") > -1)) {
- license = "EPL";
- } else if ((urlString.indexOf("cpl") > -1 || urlAnotation
- .indexOf("cpl") > -1)) {
- license = "CPL";
- }
- }
- }
- return license;
- }
-
- private String getURL() {
- String url = VALUE_NOT_FOUND;
- URLEntryModel descriptionModel = featureModel.getDescriptionModel();
- if (descriptionModel != null && descriptionModel.getURLString() != null)
- url = descriptionModel.getURLString();
- return url;
- }
-
- private String getDescription() {
- URLEntryModel descriptionModel = featureModel.getDescriptionModel();
- if (descriptionModel.getAnnotation() != null) {
- // Each description line contain maximum 80 characters.
- String[] descriptionToken = resolveFeatureProperties(
- descriptionModel.getAnnotation()).split(" ");
- String description = descriptionToken[0] + " ";
- // We add +2 because an array start at index 0 and one space is
- // removed for each token.
- int lineLenght = descriptionToken[0].length() + 2;
- int i;
- for (i = 2; i < descriptionToken.length; i++) {
- lineLenght += descriptionToken[i].length() + 2;
- if (lineLenght > 80) {
- description += descriptionToken[i - 1] + "\n";
- lineLenght = 0;
- } else {
- description += descriptionToken[i - 1] + " ";
- }
- }
- description += descriptionToken[i - 1];
- return description;
- } else
- return VALUE_NOT_FOUND;
- }
-
- private List<PackageItem> getProvides() {
- // Plugins that are part of this feature
- PluginEntryModel[] includedPlugins = featureModel
- .getPluginEntryModels();
- List<PackageItem> providesList = new ArrayList<PackageItem>();
- String pluginVersion;
- for (PluginEntryModel includedPlugin : includedPlugins) {
- PackageItem provide = new PackageItem();
- provide.setName(includedPlugin.getPluginIdentifier());
- provide.setOperator("=");
- pluginVersion = includedPlugin.getPluginVersion();
- // If the bundle version retrieve in the feature is 0.0.0, we
- // try to get it using OSGIUtils.
- if (pluginVersion.equals("0.0.0")) {
- pluginVersion = getBundleValue(provide.getName(),
- "Bundle-Version");
- if (pluginVersion == null)
- pluginVersion = "0.0.0";
- }
- provide.setVersion(pluginVersion);
- providesList.add(provide);
- }
- PackageItem featureItem = new PackageItem();
- featureItem.setName(featureModel.getFeatureIdentifier());
- featureItem.setOperator("=");
- featureItem.setVersion(featureModel.getFeatureVersion());
- providesList.add(featureItem);
- return providesList;
- }
-
- private List<PackageItem> getRequires() {
- ImportModel[] importModels = featureModel.getImportModels();
- List<PackageItem> requiresList = new ArrayList<PackageItem>();
- for (ImportModel importModel: importModels) {
- PackageItem require = new PackageItem();
- require.setName(importModel.getIdentifier());
- String pluginVersion = importModel.getVersion();
- String operator = "";
- // If the bundle version retrieve in the feature is 0.0.0, we try to
- // get it using OSGIUtils.
- if (pluginVersion.equals("0.0.0")) {
- pluginVersion = getBundleValue(require.getName(),
- "Bundle-Version");
- if (pluginVersion == null)
- pluginVersion = "0.0.0";
- }
- if (!pluginVersion.equals("0.0.0")) {
- require.setVersion(pluginVersion);
- if (importModel.getMatchingRuleName().equals(
- "greaterOrEqual"))
- operator = ">=";
- else if (importModel.getMatchingRuleName()
- .equals("greater"))
- operator = ">";
- else if (importModel.getMatchingRuleName().equals(
- "lessOrEqual"))
- operator = "<=";
- else if (importModel.getMatchingRuleName().equals("less"))
- operator = "<";
- else
- operator = "=";
- } else {
- require.setVersion("");
- }
- require.setOperator(operator);
- requiresList.add(require);
- }
- return requiresList;
- }
-
- /**
- * Get value for a given key from the feature.properties file, if the key
- * don't start with '%' we just return the given key.
- *
- * @param key
- * to find in feature.properties
- * @return the value
- */
- private String resolveFeatureProperties(String key) {
- Properties properties = new Properties();
- if (key != null && key.startsWith("%")) {
- try {
- properties.load(new FileInputStream(featurePropertiesFile));
- } catch (FileNotFoundException e) {
- // Do nothing if the feature.properties is not found
- } catch (IOException e) {
- StubbyLog.logError(e);
- }
- return properties.getProperty(key.replaceAll("%", ""));
- } else {
- return key;
- }
- }
-
- /**
- * Get bundle value for a given bundleID, bundleKey
- *
- * @param bundleID
- * the bundle
- * @param bundleKey
- * the bundle key
- * @return the value if the bundle key or null if the bundle key is not
- * found.
- */
- private String getBundleValue(String bundleID, String bundleKey) {
- try {
- return Platform.getBundle(bundleID).getHeaders().get(
- bundleKey);
- } catch (NullPointerException exception) {
- return null;
- }
- }
-
-}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/FeatureModel.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/FeatureModel.java
new file mode 100644
index 0000000000..20675ae830
--- /dev/null
+++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/FeatureModel.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpmstubby.model;
+
+import java.util.Properties;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Document;
+
+/**
+ * Gives easy access to data from the eclipse feature.xml file.
+ *
+ */
+public class FeatureModel {
+
+ private Document docroot;
+ private XPath xpath;
+ private Properties featureProperties;
+
+ /**
+ * Instantiates the model with the given XML document and preparing the
+ * XPath evaluation environment.
+ *
+ * @param docroot
+ * The document to query.
+ * @param featureProperties The properties as loaded by feature.properties.
+ */
+ public FeatureModel(Document docroot, Properties featureProperties) {
+ this.docroot = docroot;
+ this.featureProperties = featureProperties;
+ xpath = XPathFactory.newInstance().newXPath();
+ }
+
+ private String xpathEval(String path) {
+ String result = "";
+ try {
+ result = xpath.evaluate(path, docroot);
+ } catch (XPathExpressionException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ /**
+ * Get value for a given key from the feature.properties file, if the key
+ * don't start with '%' we just return the given key.
+ *
+ * @param key
+ * to find in feature.properties
+ * @return the value
+ */
+ private String resolveFeatureProperties(String key) {
+ if (key != null && key.trim().startsWith("%")) {
+ return featureProperties.getProperty(key.trim().replaceAll("%", ""));
+ } else {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the package name.
+ * It is calculated by using the feature id last segment unless the last segment
+ * is feature in which case the previous one is used.
+ * @return The package name.
+ */
+ public String getSimplePackageName() {
+ String packageName = xpathEval("/feature/@id");
+ String[] packageItems = packageName.split("\\.");
+ String name = packageItems[packageItems.length - 1];
+ if (name.equalsIgnoreCase("feature")) {
+ name = packageItems[packageItems.length - 2];
+ }
+
+ return name;
+ }
+
+ /**
+ * The simple package name with "eclipse-" prepended to make better RPM package name.
+ * @return The package
+ */
+ public String getPackageName() {
+ return "eclipse-"+getSimplePackageName();
+ }
+
+ /**
+ * Returns the feature id as retrieved with /feature/@id xpath.
+ * @return The feature id.
+ */
+ public String getFeatureId() {
+ return xpathEval("/feature/@id");
+ }
+
+ /**
+ * Returns the version as retrieved by /feature/@version xpath with .qualifier removed if any.
+ *
+ * @return The version of the feature.
+ */
+ public String getVersion() {
+ String version = xpathEval("/feature/@version");
+ version = version.replaceAll(".qualifier", "");
+ return version;
+ }
+
+ /**
+ * Returns the summary as retrieved by /feature/@label xpath.
+ *
+ * @return The package summary.
+ */
+ public String getSummary() {
+ return resolveFeatureProperties(xpathEval("/feature/@label"));
+ }
+
+ /**
+ * Returns the license.
+ * The algorithm is to look at /feature/license and/or /feature/license/@url and look for epl or cpl.
+ * Otherwise #FIX ME comment is returned
+ * @return The license of the feature.
+ */
+ public String getLicense() {
+ String urlString = resolveFeatureProperties(xpathEval("/feature/license/@url"));
+ String urlAnotation = resolveFeatureProperties(xpathEval("/feature/license"));
+ String license = "#FIXME";
+ if ((urlString != null && urlAnotation != null)) {
+ if ((urlString.indexOf("epl") > -1 || urlAnotation
+ .indexOf("epl") > -1)) {
+ license = "EPL";
+ } else if ((urlString.indexOf("cpl") > -1 || urlAnotation
+ .indexOf("cpl") > -1)) {
+ license = "CPL";
+ }
+ }
+ return license;
+ }
+
+
+
+ /**
+ * Returns the url as fetched from /feature/description/@url xpath if any.
+ * @return The url.
+ */
+ public String getURL() {
+ return xpathEval("/feature/description/@url");
+ }
+
+ /**
+ * Returns the description as fetched by /feature/description and resolved from feature.properties if needed.
+ *
+ * @return The description.
+ */
+ public String getDescription() {
+ return resolveFeatureProperties(xpathEval("/feature/description"));
+ }
+
+}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/IPackage.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/IPackage.java
deleted file mode 100644
index 1a2c9cee2b..0000000000
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/IPackage.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Alphonse Van Assche.
- * 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:
- * Alphonse Van Assche - initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.rpmstubby.model;
-
-import java.util.List;
-
-public interface IPackage {
-
- public String getName();
-
- public void setName(String name);
-
- public String getGroup();
-
- public void setGroup(String group);
-
- public String getSummary();
-
- public void setSummary(String summary);
-
- public String getDescription();
-
- public void setDescription(String description);
-
- public List<PackageItem> getRequires();
-
- public void setRequires(List<PackageItem> requires);
-
- public List<PackageItem> getProvides();
-
- public void setProvides(List<PackageItem> provides);
-
- public String getVersion();
-
- public void setVersion(String version);
-
-}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/IPackagePreamble.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/IPackagePreamble.java
deleted file mode 100644
index 7974d615c9..0000000000
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/IPackagePreamble.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Alphonse Van Assche.
- * 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:
- * Alphonse Van Assche - initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.rpmstubby.model;
-
-import java.util.List;
-
-public interface IPackagePreamble {
-
- public String getRelease();
-
- public void setRelease(String release);
-
- public String getLicense();
-
- public void setLicense(String license);
-
- public String getURL();
-
- public void setURL(String url);
-
- public List<String> getSources();
-
- public void setSources(List<String> sources);
-
- public List<String> getPaches();
-
- public void setPaches(List<String> paches);
-
- public String getBuildroot();
-
- public void setBuildroot(String buildroot);
-
- public List<PackageItem> getBuildRequires();
-
- public void setBuildRequires(List<PackageItem> buildRequires);
-
-}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/MainPackage.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/MainPackage.java
deleted file mode 100644
index be2be7e9c3..0000000000
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/MainPackage.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Alphonse Van Assche.
- * 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:
- * Alphonse Van Assche - initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.rpmstubby.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Bean representation of the main package of the RPM.
- *
- */
-public class MainPackage extends SubPackage implements IPackagePreamble {
-
- private String release;
- private String license;
- private String URL;
- private List<String> sources;
- private List<String> paches;
- private String buildroot;
- private List<PackageItem> buildRequires;
- private List<String> docFiles = new ArrayList<String>();
- private String docFilesRoot;
-
-
- /**
- * Returns the doc files for this package.
- * @return The doc files.
- */
- public List<String> getDocFiles() {
- return docFiles;
- }
-
- /**
- * Sets the doc files for this package.
- * @param docFiles The doc files.
- */
- public void setDocFiles(List<String> docFiles) {
- this.docFiles = docFiles;
- }
-
- public String getRelease() {
- return release;
- }
-
- public void setRelease(String release) {
- this.release = release;
- }
-
- public String getLicense() {
- return license;
- }
-
- public void setLicense(String license) {
- this.license = license;
- }
-
- public String getURL() {
- return URL;
- }
-
- public void setURL(String url) {
- URL = url;
- }
-
- public List<String> getSources() {
- return sources;
- }
-
- public void setSources(List<String> sources) {
- this.sources = sources;
- }
-
- public List<String> getPaches() {
- return paches;
- }
-
- public void setPaches(List<String> paches) {
- this.paches = paches;
- }
-
- public String getBuildroot() {
- return buildroot;
- }
-
- public void setBuildroot(String buildroot) {
- this.buildroot = buildroot;
- }
-
- public List<PackageItem> getBuildRequires() {
- return buildRequires;
- }
-
- public void setBuildRequires(List<PackageItem> buildRequires) {
- this.buildRequires = buildRequires;
- }
-
-
- @Override
- public String toString() {
- StringBuilder buffer = new StringBuilder();
- buffer.append(super.toString());
- buffer.append("\nRelease: ").append(release);
- buffer.append("\nLicense; ").append(license);
- buffer.append("\nURL: ").append(URL);
- if (sources == null) {
- buffer.append("\nSources: ").append("null");
- } else {
- buffer.append("\nSources: ").append(
- sources.toString());
- }
- if (paches == null) {
- buffer.append("\nPaches: ").append("null");
- } else {
- buffer.append("\nPaches: ")
- .append(paches.toString());
- }
- if (buildRequires == null) {
- buffer.append("\nBuildRequires: ").append("null");
- } else {
- buffer.append("\nBuildRequires: ").append(
- buildRequires.toString());
- }
- buffer.append("\nBuildRoot: ").append(buildroot);
- return buffer.toString();
- }
-
- /**
- * @param docFilesRoot The docFilesRoot to set
- */
- public void setDocFilesRoot(String docFilesRoot) {
- this.docFilesRoot = docFilesRoot;
- }
-
- /**
- * @return The docFilesRoot
- */
- public String getDocFilesRoot() {
- return docFilesRoot;
- }
-
-}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/PackageItem.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/PackageItem.java
deleted file mode 100644
index 2c692b01b8..0000000000
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/PackageItem.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Alphonse Van Assche.
- * 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:
- * Alphonse Van Assche - initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.rpmstubby.model;
-
-public class PackageItem {
-
- private String name;
- private String version;
- private String operator;
-
- public String getOperator() {
- return operator;
- }
-
- public void setOperator(String operator) {
- this.operator = operator;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- @Override
- public String toString() {
- StringBuilder buffer = new StringBuilder();
- buffer.append(name);
- buffer.append(" ").append(operator);
- buffer.append(" ").append(version);
- return buffer.toString();
- }
-}
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/SubPackage.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/SubPackage.java
deleted file mode 100644
index ffd0dba06d..0000000000
--- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/internal/rpmstubby/model/SubPackage.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Alphonse Van Assche.
- * 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:
- * Alphonse Van Assche - initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.internal.rpmstubby.model;
-
-import java.util.List;
-
-public class SubPackage implements IPackage {
-
- private String name;
- private String version;
- private String group;
- private String summary;
- private String description;
- private List<PackageItem> requires;
- private List<PackageItem> provides;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getGroup() {
- return group;
- }
-
- public void setGroup(String group) {
- this.group = group;
- }
-
- public String getSummary() {
- return summary;
- }
-
- public void setSummary(String summary) {
- this.summary = summary;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public List<PackageItem> getRequires() {
- return requires;
- }
-
- public void setRequires(List<PackageItem> requires) {
- this.requires = requires;
- }
-
- public List<PackageItem> getProvides() {
- return provides;
- }
-
- public void setProvides(List<PackageItem> provides) {
- this.provides = provides;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- @Override
- public String toString() {
- StringBuilder buffer = new StringBuilder();
- buffer.append("%package ").append(name);
- buffer.append("\nVersion: ").append(version);
- buffer.append("\nSummary: ").append(summary);
- buffer.append("\nGroup: ").append(group);
- if (provides == null) {
- buffer.append("\nProvides: ").append("null");
- } else {
- buffer.append("\nProvides: ").append(
- provides.toString());
- }
- if (requires == null) {
- buffer.append("\nRequires: ").append("null");
- } else {
- buffer.append("\nRequires: ").append(
- requires.toString());
- }
- buffer.append("\n\n%description ").append(name + "\n");
- buffer.append(description);
- return buffer.toString();
- }
-
-}

Back to the top