Reenable the loading of the environment profile

git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@1040043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nicolas Lalevee 2010-11-29 09:21:46 +00:00
parent f08996d4ee
commit 8cc389ea41
9 changed files with 377 additions and 127 deletions

View File

@ -27,9 +27,9 @@ import java.util.jar.Manifest;
import org.apache.ivy.ant.IvyTask;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
import org.apache.ivy.osgi.core.BundleInfo;
import org.apache.ivy.osgi.core.ExecutionEnvironmentProfileProvider;
import org.apache.ivy.osgi.core.ManifestParser;
import org.apache.ivy.osgi.repo.BundleInfoAdapter;
import org.apache.ivy.osgi.repo.osgi.ExecutionEnvironmentProfileProvider;
import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
import org.apache.tools.ant.BuildException;
@ -60,6 +60,13 @@ public class ConvertManifestTask extends IvyTask {
if (manifest == null) {
throw new BuildException("source manifest file is required for convertmanifest task");
}
if (profileProvider == null) {
try {
profileProvider = new ExecutionEnvironmentProfileProvider();
} catch (IOException e) {
throw new BuildException("Enable to load the default environment profiles");
}
}
Manifest m;
try {

View File

@ -0,0 +1,119 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.ivy.osgi.core;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import org.apache.ivy.osgi.repo.ExecutionEnvironmentProfile;
import org.apache.ivy.util.Message;
public class ExecutionEnvironmentProfileProvider {
private static final String DEFAULT_PROFILES_FILE = "jvm-packages.properties";
private static final String PACKAGE_PREFIX = "org/apache/ivy/osgi/core/";
private Map/* <String, ExecutionEnvironmentProfile> */profileList;
public ExecutionEnvironmentProfileProvider() throws IOException {
profileList = loadDefaultProfileList();
}
public ExecutionEnvironmentProfile getProfile(String profile) {
return (ExecutionEnvironmentProfile) profileList.get(profile);
}
public static Map/* <String, ExecutionEnvironmentProfile> */loadDefaultProfileList()
throws IOException {
ClassLoader loader = ExecutionEnvironmentProfileProvider.class.getClassLoader();
InputStream defaultProfilesFile = loader.getResourceAsStream(PACKAGE_PREFIX
+ DEFAULT_PROFILES_FILE);
if (defaultProfilesFile == null) {
throw new FileNotFoundException(PACKAGE_PREFIX + DEFAULT_PROFILES_FILE
+ " not found in the classpath");
}
Properties props = new Properties();
try {
props.load(defaultProfilesFile);
} finally {
defaultProfilesFile.close();
}
Map/* <String, ExecutionEnvironmentProfile> */profiles = new HashMap();
Iterator itProp = props.entrySet().iterator();
while (itProp.hasNext()) {
Entry/* <String, String> */prop = (Entry) itProp.next();
String propName = (String) prop.getKey();
if (propName.endsWith(".pkglist")) {
String profileName = propName.substring(0, propName.length() - 8);
if (!profiles.containsKey(profileName)) {
loadProfile(props, profiles, profileName);
}
}
}
return profiles;
}
private static ExecutionEnvironmentProfile loadProfile(Properties props, Map/*
* <String,
* ExecutionEnvironmentProfile
* >
*/profiles,
String name) {
ExecutionEnvironmentProfile profile = new ExecutionEnvironmentProfile(name);
// load the package for the extended profile
String extendedProfileName = props.getProperty(name + ".extends");
if (extendedProfileName != null) {
ExecutionEnvironmentProfile extendedProfile = (ExecutionEnvironmentProfile) profiles
.get(extendedProfileName);
if (extendedProfile == null) {
// not loaded yet, so load it now
extendedProfile = loadProfile(props, profiles, extendedProfileName);
}
Iterator itExtended = extendedProfile.getPkgNames().iterator();
while (itExtended.hasNext()) {
profile.addPkgName((String) itExtended.next());
}
}
// load the actual list
String pkgList = props.getProperty(name + ".pkglist");
String[] packages = pkgList.split(",");
for (int i = 0; i < packages.length; i++) {
String pkg = packages[i].trim();
if (pkg.length() != 0) {
profile.addPkgName(pkg);
}
}
profiles.put(name, profile);
Message.verbose("Execution environment profile " + profile.getName() + " loaded");
return profile;
}
}

View File

@ -0,0 +1,200 @@
# ***************************************************************
# * Licensed to the Apache Software Foundation (ASF) under one
# * or more contributor license agreements. See the NOTICE file
# * distributed with this work for additional information
# * regarding copyright ownership. The ASF licenses this file
# * to you under the Apache License, Version 2.0 (the
# * "License"); you may not use this file except in compliance
# * with the License. You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable law or agreed to in writing,
# * software distributed under the License is distributed on an
# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# * KIND, either express or implied. See the License for the
# * specific language governing permissions and limitations
# * under the License.
# ***************************************************************
OSGI_MINIMUM-1.0.pkglist =
OSGI_MINIMUM-1.1.extends = OSGI_MINIMUM-1.0
OSGI_MINIMUM-1.1.pkglist =
CDC-1.0_Foundation-1.0.pkglist = \
javax.microedition.io
CDC-1.1_Foundation-1.1.extends = CDC-1.0_Foundation-1.0
CDC-1.1_Foundation-1.1.pkglist = \
javax.microedition.pki,\
javax.security.auth.x500
J2SE-1.2.pkglist = \
javax.accessibility,\
javax.swing,\
javax.swing.border,\
javax.swing.colorchooser,\
javax.swing.event,\
javax.swing.filechooser,\
javax.swing.plaf,\
javax.swing.plaf.basic,\
javax.swing.plaf.metal,\
javax.swing.plaf.multi,\
javax.swing.table,\
javax.swing.text,\
javax.swing.text.html,\
javax.swing.text.html.parser,\
javax.swing.text.rtf,\
javax.swing.tree,\
javax.swing.undo,\
org.omg.CORBA,\
org.omg.CORBA.DynAnyPackage,\
org.omg.CORBA.ORBPackage,\
org.omg.CORBA.portable,\
org.omg.CORBA.TypeCodePackage,\
org.omg.CosNaming,\
org.omg.CosNaming.NamingContextPackage
J2SE-1.3.extends = J2SE-1.2
J2SE-1.3.pkglist = \
javax.naming,\
javax.naming.directory,\
javax.naming.event,\
javax.naming.ldap,\
javax.naming.spi,\
javax.rmi,\
javax.rmi.CORBA,\
javax.sound.midi,\
javax.sound.midi.spi,\
javax.sound.sampled,\
javax.sound.sampled.spi,\
javax.transaction,\
org.omg.CORBA_2_3,\
org.omg.CORBA_2_3.portable,\
org.omg.SendingContext,\
org.omg.stub.java.rmi
J2SE-1.4.extends = J2SE-1.3
J2SE-1.4.pkglist = \
javax.crypto,\
javax.crypto.interfaces,\
javax.crypto.spec,\
javax.imageio,\
javax.imageio.event,\
javax.imageio.metadata,\
javax.imageio.plugins.jpeg,\
javax.imageio.spi,\
javax.imageio.stream,\
javax.net,\
javax.net.ssl,\
javax.print,\
javax.print.attribute,\
javax.print.attribute.standard,\
javax.print.event,\
javax.security.auth,\
javax.security.auth.callback,\
javax.security.auth.kerberos,\
javax.security.auth.login,\
javax.security.auth.spi,\
javax.security.auth.x500,\
javax.security.cert,\
javax.sql,\
javax.transaction.xa,\
javax.xml.parsers,\
javax.xml.transform,\
javax.xml.transform.dom,\
javax.xml.transform.sax,\
javax.xml.transform.stream,\
org.ietf.jgss,\
org.omg.Dynamic,\
org.omg.DynamicAny,\
org.omg.DynamicAny.DynAnyFactoryPackage,\
org.omg.DynamicAny.DynAnyPackage,\
org.omg.IOP,\
org.omg.IOP.CodecFactoryPackage,\
org.omg.IOP.CodecPackage,\
org.omg.Messaging,\
org.omg.PortableInterceptor,\
org.omg.PortableInterceptor.ORBInitInfoPackage,\
org.omg.PortableServer,\
org.omg.PortableServer.CurrentPackage,\
org.omg.PortableServer.POAManagerPackage,\
org.omg.PortableServer.POAPackage,\
org.omg.PortableServer.portable,\
org.omg.PortableServer.ServantLocatorPackage,\
org.omg.stub.java.rmi,\
org.w3c.dom,\
org.w3c.dom.css,\
org.w3c.dom.events,\
org.w3c.dom.html,\
org.w3c.dom.stylesheets,\
org.w3c.dom.views ,\
org.xml.sax,\
org.xml.sax.ext,\
org.xml.sax.helpers
J2SE-1.5.extends = J2SE-1.4
J2SE-1.5.pkglist = \
javax.activity,\
javax.imageio.plugins.bmp,\
javax.management,\
javax.management.loading,\
javax.management.modelmbean,\
javax.management.monitor,\
javax.management.openmbean,\
javax.management.relation,\
javax.management.remote,\
javax.management.remote.rmi,\
javax.management.timer,\
javax.rmi.ssl,\
javax.security.sasl,\
javax.sql.rowset,\
javax.sql.rowset.serial,\
javax.sql.rowset.spi,\
javax.swing.plaf.synth,\
javax.xml,\
javax.xml.datatype,\
javax.xml.namespace,\
javax.xml.validation,\
org.w3c.dom.bootstrap,\
org.w3c.dom.ls,\
org.w3c.dom.ranges,\
org.w3c.dom.traversal
JavaSE-1.6.extends = J2SE-1.5
JavaSE-1.6.pkglist = \
javax.activation,\
javax.annotation,\
javax.annotation.processing,\
javax.jws,\
javax.jws.soap,\
javax.lang.model,\
javax.lang.model.element,\
javax.lang.model.type,\
javax.lang.model.util,\
javax.script,\
javax.tools,\
javax.xml.bind,\
javax.xml.bind.annotation,\
javax.xml.bind.annotation.adapters,\
javax.xml.bind.attachment,\
javax.xml.bind.helpers,\
javax.xml.bind.util,\
javax.xml.crypto,\
javax.xml.crypto.dom,\
javax.xml.crypto.dsig,\
javax.xml.crypto.dsig.dom,\
javax.xml.crypto.dsig.keyinfo,\
javax.xml.crypto.dsig.spec,\
javax.xml.soap,\
javax.xml.stream,\
javax.xml.stream.events,\
javax.xml.stream.util,\
javax.xml.transform.stax,\
javax.xml.ws,\
javax.xml.ws.handler,\
javax.xml.ws.handler.soap,\
javax.xml.ws.http,\
javax.xml.ws.soap,\
javax.xml.ws.spi

View File

@ -38,8 +38,8 @@ import org.apache.ivy.core.module.id.ModuleId;
import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.osgi.core.BundleInfo;
import org.apache.ivy.osgi.core.BundleRequirement;
import org.apache.ivy.osgi.core.ExecutionEnvironmentProfileProvider;
import org.apache.ivy.osgi.core.ExportPackage;
import org.apache.ivy.osgi.repo.osgi.ExecutionEnvironmentProfileProvider;
import org.apache.ivy.osgi.util.Version;
import org.apache.ivy.osgi.util.VersionRange;
import org.apache.ivy.plugins.matcher.ExactOrRegexpPatternMatcher;

View File

@ -52,8 +52,8 @@ import org.apache.ivy.core.resolve.IvyNode;
import org.apache.ivy.core.resolve.ResolveData;
import org.apache.ivy.core.resolve.ResolvedModuleRevision;
import org.apache.ivy.osgi.core.BundleInfo;
import org.apache.ivy.osgi.core.ExecutionEnvironmentProfileProvider;
import org.apache.ivy.osgi.obr.xml.OBRXMLParser;
import org.apache.ivy.osgi.repo.osgi.ExecutionEnvironmentProfileProvider;
import org.apache.ivy.osgi.util.Version;
import org.apache.ivy.plugins.conflict.ConflictManager;
import org.apache.ivy.plugins.latest.ArtifactInfo;

View File

@ -79,4 +79,8 @@ public class ExecutionEnvironmentProfile {
}
return true;
}
public String toString() {
return name + ":" + pkgNames;
}
}

View File

@ -26,8 +26,8 @@ import java.util.jar.Manifest;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
import org.apache.ivy.osgi.core.BundleInfo;
import org.apache.ivy.osgi.core.ExecutionEnvironmentProfileProvider;
import org.apache.ivy.osgi.core.ManifestParser;
import org.apache.ivy.osgi.repo.osgi.ExecutionEnvironmentProfileProvider;
import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParser;
import org.apache.ivy.plugins.parser.ParserSettings;
import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;

View File

@ -1,123 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.ivy.osgi.repo.osgi;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.ivy.osgi.repo.ExecutionEnvironmentProfile;
import org.apache.ivy.util.Message;
/**
* Load profiles provided by the <tt>org.eclipse.osgi</tt> bundle.
*/
public class ExecutionEnvironmentProfileProvider {
private static final String PROFILE_NAME = "osgi.java.profile.name";
private static final String SYSTEM_PACKAGES = "org.osgi.framework.system.packages";
private static final String PROFILE_LIST_FILE = "profile.list";
private static final String PACKAGE_PREFIX = "org/apache/ivy/osgi/repo/osgi/";
private static final String PROFILE_LIST = "java.profiles";
private Map/* <String, ExecutionEnvironmentProfile> */profileList;
// private static final String BOOT_DELEGATION = "org.osgi.framework.bootdelegation";
// private static final String ENVIRONMENT = "org.osgi.framework.executionenvironment";
public ExecutionEnvironmentProfileProvider() throws IOException {
profileList = loadDefaultProfileList();
}
public ExecutionEnvironmentProfile getProfile(String profile) {
return (ExecutionEnvironmentProfile) profileList.get(profile);
}
public static Map/* <String, ExecutionEnvironmentProfile> */loadDefaultProfileList()
throws IOException {
ClassLoader loader = ExecutionEnvironmentProfileProvider.class.getClassLoader();
InputStream profileListFile = loader
.getResourceAsStream(PACKAGE_PREFIX + PROFILE_LIST_FILE);
if (profileListFile == null) {
throw new FileNotFoundException(PACKAGE_PREFIX + PROFILE_LIST_FILE
+ " not found in the classpath");
}
Properties props = new Properties();
props.load(profileListFile);
String[] profileList = props.getProperty(PROFILE_LIST).split(",");
Message.debug("Loading profiles " + profileList);
Map/* <String, ExecutionEnvironmentProfile> */map = new HashMap/*
* <String,
* ExecutionEnvironmentProfile
* >
*/();
for (int i = 0; i < profileList.length; i++) {
String profileFile = profileList[i];
String p = profileFile.trim();
if (p.length() != 0) {
ExecutionEnvironmentProfile profile = load(loader
.getResourceAsStream(PACKAGE_PREFIX + p));
if (profile != null) {
Message.verbose("Execution environment profile " + profile.getName()
+ " loaded");
map.put(profile.getName(), profile);
} else {
Message.warn("Unable to load the environement profile " + PACKAGE_PREFIX + p);
}
}
}
return map;
}
public static ExecutionEnvironmentProfile load(File f) throws IOException {
return load(new FileInputStream(f));
}
public static ExecutionEnvironmentProfile load(InputStream in) throws IOException {
Properties props = new Properties();
props.load(in);
return load(props);
}
public static ExecutionEnvironmentProfile load(Properties properties) {
ExecutionEnvironmentProfile profile = new ExecutionEnvironmentProfile(
properties.getProperty(PROFILE_NAME));
String packagesList = properties.getProperty(SYSTEM_PACKAGES);
if (packagesList == null) {
Message.warn("The profile " + profile.getName()
+ " doesn't have any system package definition");
return null;
}
String[] packages = packagesList.split(",");
for (int i = 0; i < packages.length; i++) {
String pkg = packages[i];
profile.addPkgName(pkg.trim());
}
return profile;
}
}

View File

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.ivy.osgi.core;
import java.util.Map;
import org.apache.ivy.osgi.core.ExecutionEnvironmentProfileProvider;
import org.apache.ivy.osgi.repo.ExecutionEnvironmentProfile;
import junit.framework.TestCase;
public class ExecutionEnvironmentProfileLoaderTest extends TestCase {
public void testLoad() throws Exception {
Map/* <String, ExecutionEnvironmentProfile> */ profiles = ExecutionEnvironmentProfileProvider.loadDefaultProfileList();
assertEquals(9, profiles.size());
assertEquals(0, ((ExecutionEnvironmentProfile) profiles.get("OSGI_MINIMUM-1.0")).getPkgNames().size());
assertEquals(0, ((ExecutionEnvironmentProfile) profiles.get("OSGI_MINIMUM-1.1")).getPkgNames().size());
assertEquals(1, ((ExecutionEnvironmentProfile) profiles.get("CDC-1.0_Foundation-1.0")).getPkgNames().size());
assertEquals(3, ((ExecutionEnvironmentProfile) profiles.get("CDC-1.1_Foundation-1.1")).getPkgNames().size());
assertEquals(24, ((ExecutionEnvironmentProfile) profiles.get("J2SE-1.2")).getPkgNames().size());
assertEquals(40, ((ExecutionEnvironmentProfile) profiles.get("J2SE-1.3")).getPkgNames().size());
assertEquals(95, ((ExecutionEnvironmentProfile) profiles.get("J2SE-1.4")).getPkgNames().size());
assertEquals(120, ((ExecutionEnvironmentProfile) profiles.get("J2SE-1.5")).getPkgNames().size());
assertEquals(154, ((ExecutionEnvironmentProfile) profiles.get("JavaSE-1.6")).getPkgNames().size());
}
}