Skip to content

Commit

Permalink
Merge pull request #12 from laeubi/master
Browse files Browse the repository at this point in the history
Some fixes and improvements
  • Loading branch information
nilshartmann committed Mar 10, 2014
2 parents 2f277d5 + d899e59 commit 6e2b148
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 61 deletions.
Expand Up @@ -11,6 +11,8 @@
**********************************************************************/
package org.ant4eclipse.ant.pde;

import java.io.File;

import org.ant4eclipse.lib.core.Assure;
import org.ant4eclipse.lib.core.util.Utilities;
import org.ant4eclipse.lib.pde.internal.tools.ExpansionDirectory;
Expand All @@ -23,8 +25,6 @@
import org.apache.tools.ant.types.FileList.FileName;
import org.apache.tools.ant.types.PatternSet;

import java.io.File;

/**
* <p>
* Helper class to create an ant {@link FileList} that contains all files that belongs to a native launcher for a
Expand Down Expand Up @@ -77,16 +77,14 @@ public static FileList getNativeLauncher(TargetPlatform targetPlatform) {
* eclipse.exe and eclipsec.exe).
*/
private static FileList getNativeLauncherFromExecutableFeature(TargetPlatform targetPlatform) {

if (!targetPlatform.hasFeatureDescription(FEATURE_ORG_ECLIPSE_EQUINOX_EXECUTABLE)) {
// return null if feature doesn't exist
return null;
}
// get the executable feature from the target platform
FeatureDescription featureDescription = targetPlatform
.getFeatureDescription(FEATURE_ORG_ECLIPSE_EQUINOX_EXECUTABLE);

// return null if feature doesn't exist
if (featureDescription == null) {
return null;
}

// get the platform configuration
String ws = targetPlatform.getTargetPlatformConfiguration().getWindowingSystem();
String os = targetPlatform.getTargetPlatformConfiguration().getOperatingSystem();
Expand All @@ -96,7 +94,7 @@ private static FileList getNativeLauncherFromExecutableFeature(TargetPlatform ta
if (featureDescription.isFeatureProject()) {
// TODO
throw new RuntimeException(
"The feature 'org.eclipse.equinox.executable' has to be a exported feature, not a feature project.");
"The feature 'org.eclipse.equinox.executable' has to be an exported feature, not a feature project.");
}

// case 1: feature 'org.eclipse.equinox.executable' is a directory
Expand Down
Expand Up @@ -34,7 +34,7 @@ protected void doExecute() {

@Override
protected void preconditions() throws BuildException {
if (this._workspaceId == null || this._workspaceId.isEmpty()) {
if (this._workspaceId == null || this._workspaceId.length() == 0) {
throw new BuildException("Parameter 'workspaceId' must be set");
}
}
Expand Down
Expand Up @@ -11,13 +11,13 @@
**********************************************************************/
package org.ant4eclipse.lib.jdt.internal.model.jre;

import java.io.File;

import org.ant4eclipse.lib.core.Assure;
import org.ant4eclipse.lib.core.data.Version;
import org.ant4eclipse.lib.jdt.model.jre.JavaProfile;
import org.ant4eclipse.lib.jdt.model.jre.JavaRuntime;

import java.io.File;

/**
* <p>
* Defines a java runtime environment.
Expand All @@ -26,25 +26,25 @@
* @author Daniel Kasmeroglu (daniel.kasmeroglu@kasisoft.net)
* @author Gerd W&uuml;therich (gerd@gerd-wuetherich.de)
*/
public class JavaRuntimeImpl implements JavaRuntime {
public final class JavaRuntimeImpl implements JavaRuntime {

/** the id */
private String _id = null;
private final String _id;

/** the location */
private File _location = null;
private final File _location;

/** the version */
private Version _javaVersion = null;
private final Version _javaVersion;

/** the version */
private Version _javaSpecificationVersion = null;
private final Version _javaSpecificationVersion;

/** - */
private JavaProfile _javaProfile;
private final JavaProfile _javaProfile;

/** the libraries */
private File[] _libraries = new File[0];
private File[] _libraries = new File[0];

/**
* <p>
Expand Down Expand Up @@ -98,8 +98,7 @@ public File[] getLibraries() {
}

/**
* @see org.ant4eclipse.lib.jdt.model.jre.JavaRuntime#isJavaVersion(net.sf.ant4eclipse.model.jdt.jre.JavaRuntimeImpl.Version
* )
* {@inheritDoc}
*/
public boolean isJavaVersion(Version version) {
return (version.getMajor() == this._javaVersion.getMajor()) && (version.getMinor() == this._javaVersion.getMinor());
Expand Down
Expand Up @@ -77,6 +77,9 @@ private JavaRuntime registerJavaRuntime(String id, File location, String extDirs
List<File> jreFiles, boolean isDefault) {
Assure.nonEmpty("id", id);
Assure.isDirectory("location", location);
A4ELogging.info(
"registerJavaRuntime: id = %s, location = %s, extDirs = %s, endorsedDirs = %s, jreFiles = %s, isDefault = %s",
id, location, extDirs, endorsedDirs, jreFiles, isDefault);

JavaRuntime javaRuntime = JavaRuntimeLoader.loadJavaRuntime(id, location, extDirs, endorsedDirs, jreFiles);

Expand Down
Expand Up @@ -11,10 +11,10 @@
**********************************************************************/
package org.ant4eclipse.lib.jdt.model.jre;

import org.ant4eclipse.lib.core.data.Version;

import java.io.File;

import org.ant4eclipse.lib.core.data.Version;

/**
* <p>
* An object of type {@link JavaRuntime} represents a specific java runtime environment. You can create an instanceof
Expand Down Expand Up @@ -114,4 +114,11 @@ public interface JavaRuntime {
* @return the java profile that describes this java runtime.
*/
JavaProfile getJavaProfile();

/**
*
* @param version
* @return <code>true</code> if this version amtches the version of the {@link JavaRuntime}
*/
boolean isJavaVersion(Version version);
}
Expand Up @@ -11,11 +11,11 @@
**********************************************************************/
package org.ant4eclipse.lib.pde.internal.tools;

import java.util.List;

import org.eclipse.osgi.service.resolver.BundleDescription;
import org.osgi.framework.Version;

import java.util.List;

/**
* <p>
* A {@link BundleAndFeatureSet} represents a set of bundles and features that are stored in a specific location. A
Expand Down
Expand Up @@ -242,11 +242,7 @@ private List<BundleDescription> getAllBundleDescriptions(boolean preferProjects)
public FeatureDescription getFeatureDescription(String id, Version version) {
Assure.nonEmpty("id", id);

if (version == null) {
return getFeatureDescription(id);
}

if (version.equals(Version.emptyVersion)) {
if (version == null || version.equals(Version.emptyVersion)) {
return getFeatureDescription(id);
}

Expand All @@ -255,39 +251,42 @@ public FeatureDescription getFeatureDescription(String id, Version version) {

//
if (featureDescription != null) {
A4ELogging.debug("Feature '%s' with version '%s' found in plugin project set", id, version);
return featureDescription;
}

for (BundleAndFeatureSet bundleSet : this._binaryBundleSets) {
featureDescription = bundleSet.getFeatureDescription(id, version);
if (featureDescription != null) {
A4ELogging.debug("Feature '%s' with version '%s' found in binary bundle set", id, version);
return featureDescription;
}
}
// TODO
A4ELogging.error("Could not resolve feature '%s' in version '%s'.", id, version);
//
return null;
throw new IllegalArgumentException("Feature with id '" + id + "' and version '" + version
+ "' not found in target or project set");
}

/**
* {@inheritDoc}
*/
public boolean hasFeatureDescription(String id, Version version) {
return getFeatureDescription(id, version) != null;
try {
getFeatureDescription(id, version);
return true;
} catch (RuntimeException e) {
A4ELogging.debug("Could not find feature '%s' in version '%s' Problem %s.", id, version, e);
return false;
}
}

/**
* {@inheritDoc}
*/
public FeatureDescription getFeatureDescription(String id) {
Assure.nonEmpty("id", id);

//
FeatureDescription featureDescription = this._pluginProjectSet.getFeatureDescription(id);

//
if (featureDescription != null) {
A4ELogging.debug("Feature '%s' found in plugin project set", id);
return featureDescription;
}

Expand All @@ -304,15 +303,19 @@ public FeatureDescription getFeatureDescription(String id) {
if (featureDescription != null && featureDescription.getFeatureManifest().getId().equals(id)) {
if (result == null) {
result = featureDescription;
A4ELogging.debug("Feature '%s' found in binary bundle set", id);
} else {
// the current feature description has a higher version, so use this one
if (result.getFeatureManifest().getVersion().compareTo(featureDescription.getFeatureManifest().getVersion()) < 0) {
A4ELogging.debug("Higher version for feature '%s' found in binary bundle set", id);
result = featureDescription;
}
}
}
}

if (result == null) {
throw new IllegalArgumentException("Feature with id '" + id + "' not found in target or project set");
}
// return result
return result;
}
Expand All @@ -321,7 +324,13 @@ public FeatureDescription getFeatureDescription(String id) {
* {@inheritDoc}
*/
public boolean hasFeatureDescription(String id) {
return getFeatureDescription(id) != null;
try {
getFeatureDescription(id);
return true;
} catch (RuntimeException e) {
A4ELogging.debug("Could not find feature '%s' Problem %s.", id, e);
return false;
}
}

public boolean matchesPlatformFilter(String id) {
Expand Down Expand Up @@ -478,22 +487,23 @@ private void resolveIncludes(FeatureManifest manifest, ResolvedFeature resolvedF
if (matches(includes.getOperatingSystem(), includes.getMachineArchitecture(), includes.getWindowingSystem(),
includes.getLocale())) {

FeatureDescription featureDescription = null;
if (includes.getVersion().equals(Version.emptyVersion)) {
featureDescription = getFeatureDescription(includes.getId());
} else {
featureDescription = getFeatureDescription(includes.getId(), includes.getVersion());
}
if (featureDescription == null) {
// TODO: NLS
FeatureDescription featureDescription;
try {
if (includes.getVersion().equals(Version.emptyVersion)) {
featureDescription = getFeatureDescription(includes.getId());
} else {
featureDescription = getFeatureDescription(includes.getId(), includes.getVersion());
}
} catch (IllegalStateException e) {
throw new RuntimeException("Can't resolve included feature '" + includes.getId() + "_"
+ includes.getVersion() + "'.");
} catch (IllegalArgumentException e) {
throw new RuntimeException("No Feature found for included feature '" + includes.getId() + "_"
+ includes.getVersion() + "'.");
} else {
result.add(new Pair<Includes, FeatureDescription>(includes, featureDescription));
}
result.add(new Pair<Includes, FeatureDescription>(includes, featureDescription));
}
}

resolvedFeature.setIncludesToFeatureDescriptionList(result);
}

Expand Down
Expand Up @@ -11,6 +11,8 @@
**********************************************************************/
package org.ant4eclipse.lib.pde.model.product;

import java.io.InputStream;

import org.ant4eclipse.lib.core.Assure;
import org.ant4eclipse.lib.core.exception.Ant4EclipseException;
import org.ant4eclipse.lib.core.util.Utilities;
Expand All @@ -20,8 +22,6 @@
import org.ant4eclipse.lib.pde.tools.BundleStartRecord;
import org.osgi.framework.Version;

import java.io.InputStream;

/**
* <p>
* Parser for an eclipse product definition (<code>*.product</code>).
Expand Down Expand Up @@ -150,7 +150,9 @@ public static final ProductDefinition parseProductDefinition(InputStream inputst
String[] featureids = featureidquery.getResult();
String[] featureversions = featureversionquery.getResult();
for (int i = 0; i < featureids.length; i++) {
result.addFeature(featureids[i], new Version(featureversions[i]));
String version = i < featureversions.length ? featureversions[i] : null;
result.addFeature(featureids[i], version != null && version.length() > 0 ? new Version(version)
: Version.emptyVersion);
}

String[] configids = configidquery.getResult();
Expand Down
Expand Up @@ -73,10 +73,14 @@ public interface TargetPlatform {
* the id of the requested feature (must not be null)
* @param version
* the version of the requested feature (maybe null)
* @return the feature description for the feature with the given id and version or <code>null</code> value is
* returned if no such feature is found.
* @return the feature description for the feature with the given id and version
* @throws IllegalArgumentException
* if the feature with the given ID and version can't be found
* @throws IllegalStateException
* if the feature with the given ID can't be resolved
*/
FeatureDescription getFeatureDescription(String id, Version version);
FeatureDescription getFeatureDescription(String id, Version version) throws IllegalArgumentException,
IllegalStateException;

/**
* <p>
Expand All @@ -99,10 +103,14 @@ public interface TargetPlatform {
*
* @param id
* the id of the requested feature (must not be null)
* @return the feature description for the feature with the given id or <code>null</code> value is returned if no such
* feature is found.
* @return the feature description for the feature with the given id
*
* @throws IllegalArgumentException
* if the feature with the given ID and version can't be found
* @throws IllegalStateException
* if the feature with the given ID can't be resolved
*/
FeatureDescription getFeatureDescription(String id);
FeatureDescription getFeatureDescription(String id) throws IllegalArgumentException, IllegalStateException;

/**
* <p>
Expand Down

0 comments on commit 6e2b148

Please sign in to comment.