geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1061636 - in /geronimo/server/trunk: framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/ framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/ framework/modules/geronimo-deployment/src/...
Date Fri, 21 Jan 2011 05:10:17 GMT
Author: xuhaihong
Date: Fri Jan 21 05:10:17 2011
New Revision: 1061636

URL: http://svn.apache.org/viewvc?rev=1061636&view=rev
Log:
GERONIMO-5680 Remove dynamic import * and use calculated import packages on the runtime, only for deployed applications now

Added:
    geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/IllegalConfigurationException.java
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/DummyExportPackagesSelector.java
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ExportPackagesSelector.java
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ParentFirstExportPackagesSelector.java
Modified:
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/SingleFileHotDeployerTest.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/AbstractRepository.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Environment.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java
    geronimo/server/trunk/plugins/client/client/src/main/history/dependencies.xml
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/test/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java
    geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/test/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTestSupport.java
    geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/history/dependencies.xml
    geronimo/server/trunk/plugins/openejb/openejb/src/main/history/dependencies.xml

Added: geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/IllegalConfigurationException.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/IllegalConfigurationException.java?rev=1061636&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/IllegalConfigurationException.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/IllegalConfigurationException.java Fri Jan 21 05:10:17 2011
@@ -0,0 +1,36 @@
+/**
+ *  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.geronimo.common;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IllegalConfigurationException extends Exception {
+
+    public IllegalConfigurationException(String message) {
+        super(message);
+    }
+
+    public IllegalConfigurationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public IllegalConfigurationException(Throwable cause) {
+        super(cause);
+    }
+}

Modified: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java Fri Jan 21 05:10:17 2011
@@ -43,6 +43,9 @@ import javax.xml.bind.JAXBException;
 import javax.xml.stream.XMLStreamException;
 
 import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.common.IllegalConfigurationException;
+import org.apache.geronimo.deployment.util.osgi.DummyExportPackagesSelector;
+import org.apache.geronimo.deployment.util.osgi.OSGiMetaDataBuilder;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GAttributeInfo;
@@ -237,7 +240,7 @@ public class DeploymentContext {
         env.addToBundleClassPath(bundleClassPath);
         env.setBundleActivator(null);
         env.addDynamicImportPackage("*");
-        
+
         Manifest manifest;
         try {
             manifest = env.getManifest();
@@ -543,13 +546,26 @@ public class DeploymentContext {
             environment.setBundleActivator(ConfigurationActivator.class.getName());
         }
         List<GBeanData> gbeans = new ArrayList<GBeanData>(configuration.getGBeans().values());
-        Collections.sort(gbeans, new GBeanData.PriorityComparator());        
-        LinkedHashSet<String> imports = getImports(gbeans);
-        addImport(imports, environment.getBundleActivator());
-        environment.addImportPackages(imports);
+        Collections.sort(gbeans, new GBeanData.PriorityComparator());
+
+        OSGiMetaDataBuilder osgiMetaDataBuilder = null;
+        //TODO Import package calculation is only used for deployed applications, should be use the same way for car package later
+        if (System.getProperty("geronimo.build.car") == null) {
+            osgiMetaDataBuilder = new OSGiMetaDataBuilder(bundleContext);
+        } else {
+            LinkedHashSet<String> imports = getImports(gbeans);
+            addImport(imports, environment.getBundleActivator());
+            environment.addImportPackages(imports);
+            environment.addDynamicImportPackage("*");
+            osgiMetaDataBuilder = new OSGiMetaDataBuilder(bundleContext, new DummyExportPackagesSelector());
+        }
+
+        try {
+            osgiMetaDataBuilder.build(environment);
+        } catch (IllegalConfigurationException e) {
+            throw new DeploymentException(e);
+        }
 
-        environment.addDynamicImportPackage("*");
-        
         if (tempBundle != null) {
             try {
                 createPluginMetadata();

Added: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/DummyExportPackagesSelector.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/DummyExportPackagesSelector.java?rev=1061636&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/DummyExportPackagesSelector.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/DummyExportPackagesSelector.java Fri Jan 21 05:10:17 2011
@@ -0,0 +1,36 @@
+/**
+ *  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.geronimo.deployment.util.osgi;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DummyExportPackagesSelector implements ExportPackagesSelector {
+
+    @Override
+    public Map<Long, Set<ExportPackage>> select(OSGiBuildContext selectContext) {
+           return Collections.<Long, Set<ExportPackage>>emptyMap();
+    }
+
+}

Added: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ExportPackagesSelector.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ExportPackagesSelector.java?rev=1061636&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ExportPackagesSelector.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ExportPackagesSelector.java Fri Jan 21 05:10:17 2011
@@ -0,0 +1,31 @@
+/**
+ *  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.geronimo.deployment.util.osgi;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface ExportPackagesSelector {
+
+    public Map<Long,Set<ExportPackage>> select(OSGiBuildContext selectContext);
+}

Added: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java?rev=1061636&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java Fri Jan 21 05:10:17 2011
@@ -0,0 +1,99 @@
+/**
+ *  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.geronimo.deployment.util.osgi;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.geronimo.kernel.repository.Dependency;
+import org.apache.geronimo.system.configuration.DependencyManager;
+import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HighVersionFirstExportPackagesSelector implements ExportPackagesSelector {
+
+    private static final Logger logger = LoggerFactory.getLogger(HighVersionFirstExportPackagesSelector.class);
+
+    @Override
+    public Map<Long, Set<ExportPackage>> select(OSGiBuildContext context) {
+        Map<Long, Set<ExportPackage>> bundleIdExportPackages = new HashMap<Long, Set<ExportPackage>>();
+        Map<String, Version> packageNameVersionMap = new HashMap<String, Version>();
+        DependencyManager dependencyManager = context.getDependencyManager();
+        for (Dependency dependency : context.getEnvironment().getDependencies()) {
+            Bundle dependentBundle = dependencyManager.getBundle(dependency.getArtifact());
+            if (dependentBundle == null) {
+                logger.warn("Fail to resolve the bundle corresponding to the artifact " + dependency.getArtifact() + ", its export packages are ignored");
+                continue;
+            }
+            Set<ExportPackage> exportPackages = context.getEffectExportPackages(dependentBundle.getBundleId());
+            if (exportPackages.size() > 0) {
+                bundleIdExportPackages.put(dependentBundle.getBundleId(), exportPackages);
+                recordHighestPackageVersion(packageNameVersionMap, exportPackages);
+            }
+            for (Long parentDependentBundleId : dependencyManager.getFullDependentBundleIds(dependentBundle)) {
+                if (!bundleIdExportPackages.containsKey(parentDependentBundleId)) {
+                    Set<ExportPackage> parentExportPackages = context.getEffectExportPackages(parentDependentBundleId);
+                    if (parentExportPackages.size() > 0) {
+                        bundleIdExportPackages.put(parentDependentBundleId, parentExportPackages);
+                        recordHighestPackageVersion(packageNameVersionMap, parentExportPackages);
+                    }
+                }
+            }
+        }
+
+        //Add framework bundle export packages
+        Set<ExportPackage> systemExportPackages = context.getEffectExportPackages(0L);
+        bundleIdExportPackages.put(0L, systemExportPackages);
+        recordHighestPackageVersion(packageNameVersionMap, systemExportPackages);
+
+        for (Iterator<Entry<Long, Set<ExportPackage>>> entryIt = bundleIdExportPackages.entrySet().iterator(); entryIt.hasNext();) {
+            Entry<Long, Set<ExportPackage>> entry = entryIt.next();
+            for (Iterator<ExportPackage> it = entry.getValue().iterator(); it.hasNext();) {
+                ExportPackage exportPackage = it.next();
+                Version highestVersion = packageNameVersionMap.get(exportPackage.getName());
+                //Use != operator should be enough
+                if (highestVersion != exportPackage.getVersion()) {
+                    it.remove();
+                }
+            }
+            if (entry.getValue().size() == 0) {
+                entryIt.remove();
+            }
+        }
+        packageNameVersionMap.clear();
+        return bundleIdExportPackages;
+    }
+
+    private void recordHighestPackageVersion(Map<String, Version> packageNameVersionMap, Set<ExportPackage> exportPackages) {
+        for (ExportPackage exportPackage : exportPackages) {
+            Version existedVersion = packageNameVersionMap.get(exportPackage.getName());
+            if (existedVersion == null || exportPackage.getVersion().compareTo(existedVersion) > 0) {
+                packageNameVersionMap.put(exportPackage.getName(), exportPackage.getVersion());
+            }
+        }
+    }
+}

Added: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java?rev=1061636&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java Fri Jan 21 05:10:17 2011
@@ -0,0 +1,100 @@
+/**
+ *  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.geronimo.deployment.util.osgi;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.system.configuration.DependencyManager;
+import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OSGiBuildContext {
+
+    private List<String> hiddenImportPackageNamePrefixes;
+
+    private Set<String> hiddenImportPackageNames;
+
+    private DependencyManager dependencyManager;
+
+    private Environment environment;
+
+    private boolean inverseClassLoading;
+
+    public OSGiBuildContext(Environment environment, List<String> hiddenImportPackageNamePrefixes, Set<String> hiddenImportPackageNames, DependencyManager dependencyManager,
+            boolean inverseClassLoading) {
+        this.hiddenImportPackageNamePrefixes = hiddenImportPackageNamePrefixes;
+        this.hiddenImportPackageNames = hiddenImportPackageNames;
+        this.dependencyManager = dependencyManager;
+        this.environment = environment;
+        this.inverseClassLoading = inverseClassLoading;
+    }
+
+    private Map<String, Object> mergeAttributes = new HashMap<String, Object>();
+
+    public Object getAttribute(String name) {
+        return mergeAttributes.get(name);
+    }
+
+    public void setAttribute(String name, Object value) {
+        mergeAttributes.put(name, value);
+    }
+
+    public boolean isInverseClassLoading() {
+        return inverseClassLoading;
+    }
+
+    public boolean isHiddenExportPackage(ExportPackage exportPackage) {
+        String packageName = exportPackage.getName();
+        if (hiddenImportPackageNames.contains(packageName)) {
+            return true;
+        }
+        for (String hiddenImportPackageNamePrefix : hiddenImportPackageNamePrefixes) {
+            if (packageName.startsWith(hiddenImportPackageNamePrefix)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public DependencyManager getDependencyManager() {
+        return dependencyManager;
+    }
+
+    public Environment getEnvironment() {
+        return environment;
+    }
+
+    public Set<ExportPackage> getEffectExportPackages(Long bundleId) {
+        Set<ExportPackage> exportPackages = new HashSet<ExportPackage>(dependencyManager.getExportedPackages(bundleId));
+        for (Iterator<ExportPackage> it = exportPackages.iterator(); it.hasNext();) {
+            ExportPackage exportPackage = it.next();
+            if (isHiddenExportPackage(exportPackage)) {
+                it.remove();
+            }
+        }
+        return exportPackages;
+    }
+}

Added: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java?rev=1061636&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java Fri Jan 21 05:10:17 2011
@@ -0,0 +1,162 @@
+/**
+ *  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.geronimo.deployment.util.osgi;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.common.IllegalConfigurationException;
+import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.system.configuration.DependencyManager;
+import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
+import org.apache.xbean.osgi.bundle.util.HeaderParser;
+import org.apache.xbean.osgi.bundle.util.HeaderParser.HeaderElement;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OSGiMetaDataBuilder {
+
+    private static final Version ZERO_VERSION = new Version(0, 0, 0);
+
+    private BundleContext bundleContext;
+
+    private ExportPackagesSelector exportPackagesSelector;
+
+    public OSGiMetaDataBuilder(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+        this.exportPackagesSelector = new HighVersionFirstExportPackagesSelector();
+    }
+
+    public OSGiMetaDataBuilder(BundleContext bundleContext, ExportPackagesSelector exportPackagesSelector) {
+        this.bundleContext = bundleContext;
+        this.exportPackagesSelector = exportPackagesSelector;
+    }
+
+    public void build(Environment environment) throws IllegalConfigurationException {
+        processClassloadingRules(environment);
+        ServiceReference serviceReference = null;
+        try {
+            serviceReference = bundleContext.getServiceReference(DependencyManager.class.getName());
+            DependencyManager dependencyManager = null;
+            if (serviceReference != null) {
+                dependencyManager = (DependencyManager) bundleContext.getService(serviceReference);
+            }
+            OSGiBuildContext context = createOSGiBuildContext(environment, dependencyManager);
+            processImportPackages(context);
+        } finally {
+            if (serviceReference != null) {
+                bundleContext.ungetService(serviceReference);
+            }
+        }
+    }
+
+    protected void processClassloadingRules(Environment environment) {
+        //Process Hidden Class
+        for (String hiddenClassPrefix : environment.getClassLoadingRules().getHiddenRule().getClassPrefixes()) {
+            environment.addImportPackage("!" + hiddenClassPrefix);
+        }
+        //Non-Overridable-Classes
+        /*for (String hiddenClassPrefix : environment.getClassLoadingRules().getHiddenRule().getClassPrefixes()) {
+            environment.getImportPackages().add(hiddenClassPrefix);
+        }*/
+    }
+
+    protected OSGiBuildContext createOSGiBuildContext(Environment environment, DependencyManager dependencyManager) throws IllegalConfigurationException {
+        List<String> hiddenImportPackageNamePrefixes = new ArrayList<String>();
+        Set<String> hiddenImportPackageNames = new HashSet<String>();
+
+        Set<String> removedImportPackages = new HashSet<String>();
+        for (String initialImportPackageName : environment.getImportPackages()) {
+            String importPackageName = initialImportPackageName.trim();
+            if (importPackageName.length() == 0) {
+                removedImportPackages.add(initialImportPackageName);
+                continue;
+            }
+            if (importPackageName.startsWith("!")) {
+                importPackageName = importPackageName.substring(1);
+                if (importPackageName.endsWith("*")) {
+                    hiddenImportPackageNamePrefixes.add(importPackageName.substring(0, importPackageName.length() - 1));
+                } else {
+                    hiddenImportPackageNames.add(importPackageName);
+                }
+                removedImportPackages.add(initialImportPackageName);
+            } else {
+                if (importPackageName.endsWith("*")) {
+                    throw new IllegalConfigurationException("wildchar * could not be used in the import-package " + importPackageName + " without ! prefix");
+                }
+                //If the users configured import packages, those will take the highest precedence.
+                List<HeaderElement> elements = HeaderParser.parseHeader(importPackageName);
+                for (HeaderElement headerElement : elements) {
+                    hiddenImportPackageNames.add(headerElement.getName());
+                }
+            }
+        }
+        environment.removeImportPackages(removedImportPackages);
+
+        Set<String> removedDynamicImportPackages = new HashSet<String>();
+        for (String initialDynamicImportPackageName : environment.getDynamicImportPackages()) {
+            String dynamicImportPackageName = initialDynamicImportPackageName.trim();
+            if (dynamicImportPackageName.length() == 0) {
+                removedDynamicImportPackages.add(initialDynamicImportPackageName);
+                continue;
+            }
+            if (dynamicImportPackageName.startsWith("!")) {
+                throw new IllegalConfigurationException("DynamicImport-Package " + dynamicImportPackageName + " could not configured with ! prefix");
+            } else {
+                List<HeaderElement> elements = HeaderParser.parseHeader(dynamicImportPackageName);
+                for (HeaderElement headerElement : elements) {
+                    hiddenImportPackageNames.add(headerElement.getName());
+                }
+            }
+        }
+        environment.removeDynamicImportPackages(removedDynamicImportPackages);
+
+        return new OSGiBuildContext(environment, hiddenImportPackageNamePrefixes, hiddenImportPackageNames, dependencyManager, environment.getClassLoadingRules().isInverseClassLoading());
+    }
+
+    protected void processImportPackages(OSGiBuildContext context) {
+        Environment environment = context.getEnvironment();
+        Map<Long, Set<ExportPackage>> selectedExportPackages = exportPackagesSelector.select(context);
+        for (Map.Entry<Long, Set<ExportPackage>> entry : selectedExportPackages.entrySet()) {
+            if (context.isInverseClassLoading()) {
+                for (ExportPackage exportPackage : entry.getValue()) {
+                    String importPackageName = toImportPackageName(exportPackage);
+                    environment.addDynamicImportPackage(importPackageName);
+                }
+            } else {
+                for (ExportPackage exportPackage : entry.getValue()) {
+                    String importPackageName = toImportPackageName(exportPackage);
+                    environment.addImportPackage(importPackageName);
+                }
+            }
+        }
+        selectedExportPackages.clear();
+    }
+
+    protected String toImportPackageName(ExportPackage exportPackage) {
+        //TODO If mandatory attribute exists, do we need to handle it ?
+        return exportPackage.getVersion().equals(ZERO_VERSION) ? exportPackage.getName() : exportPackage.getName() + ";version=" + exportPackage.getVersion();
+    }
+}

Added: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ParentFirstExportPackagesSelector.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ParentFirstExportPackagesSelector.java?rev=1061636&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ParentFirstExportPackagesSelector.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ParentFirstExportPackagesSelector.java Fri Jan 21 05:10:17 2011
@@ -0,0 +1,36 @@
+/**
+ *  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.geronimo.deployment.util.osgi;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ParentFirstExportPackagesSelector implements ExportPackagesSelector {
+
+    @Override
+    public Map<Long,Set<ExportPackage>> select(OSGiBuildContext context) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Modified: geronimo/server/trunk/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/SingleFileHotDeployerTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/SingleFileHotDeployerTest.java?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/SingleFileHotDeployerTest.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/SingleFileHotDeployerTest.java Fri Jan 21 05:10:17 2011
@@ -21,8 +21,10 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Hashtable;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.jar.JarFile;
 
 import org.apache.geronimo.common.DeploymentException;
@@ -44,7 +46,11 @@ import org.apache.geronimo.kernel.reposi
 import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.Repository;
+import org.apache.geronimo.system.configuration.DependencyManager;
 import org.apache.geronimo.testsupport.TestSupport;
+import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 
 
 /**
@@ -90,6 +96,7 @@ public class SingleFileHotDeployerTest e
         }
         bundleContext = new MockBundleContext(getClass().getClassLoader(), BASEDIR.getAbsolutePath(), null, Collections.singletonMap(baseLocation, NEW_ID));
         ((MockBundleContext)bundleContext).setConfigurationManager(new MockConfigurationManager());
+        bundleContext.registerService(DependencyManager.class.getName(), new MockDependencyManager(bundleContext, Collections.<Repository> emptyList(), null), new Hashtable());
         File someFile = new File(dir, "someFile");
         someFile.createNewFile();
 
@@ -106,7 +113,7 @@ public class SingleFileHotDeployerTest e
     }
 
     protected void tearDown() throws Exception {
-        store.cleanup(); 
+        store.cleanup();
         super.tearDown();
     }
 
@@ -327,6 +334,29 @@ public class SingleFileHotDeployerTest e
     }
 */
 
+    private class MockDependencyManager extends DependencyManager {
+
+        public MockDependencyManager(BundleContext bundleContext, Collection<Repository> repositories, ArtifactResolver artifactResolver) {
+            super(bundleContext, repositories, artifactResolver);
+        }
+
+        @Override
+        public synchronized Set<ExportPackage> getExportedPackages(Bundle bundle) {
+           return Collections.<ExportPackage>emptySet();
+        }
+
+        @Override
+        public List<Bundle> getDependentBundles(Bundle bundle) {
+            return Collections.<Bundle>emptyList();
+        }
+
+        @Override
+        public Bundle getBundle(Artifact artifact) {
+            return null;
+        }
+
+    }
+
     private class MockConfigurationManager extends org.apache.geronimo.kernel.mock.MockConfigurationManager {
         private ConfigurationData loadedConfigurationData;
 

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/AbstractRepository.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/AbstractRepository.java?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/AbstractRepository.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/AbstractRepository.java Fri Jan 21 05:10:17 2011
@@ -125,9 +125,13 @@ public abstract class AbstractRepository
         ArtifactTypeHandler typeHandler = typeHandlers.get(destination.getType());
         if (typeHandler == null) typeHandler = DEFAULT_TYPE_HANDLER;
         typeHandler.install(source, size, destination, monitor, location);
-        
+
         if (destination.getType().equalsIgnoreCase("car")) {
             log.debug("Installed module configuration; id={}; location={}", destination, location);
         }
     }
+
+    public File getRootFile() {
+        return rootFile;
+    }
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Environment.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Environment.java?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Environment.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Environment.java Fri Jan 21 05:10:17 2011
@@ -126,6 +126,14 @@ public class Environment implements Seri
         this.bundleClassPath.add(bundleClassPath);
     }
 
+    public void removeBundleClassPath(Collection<String> bundleClassPath) {
+        this.bundleClassPath.removeAll(bundleClassPath);
+    }
+
+    public void removeBundleClassPath(String bundleClassPath) {
+        this.bundleClassPath.remove(bundleClassPath);
+    }
+
     public List<String> getBundleClassPath() {
         return Collections.unmodifiableList(new ArrayList<String>(bundleClassPath));
     }
@@ -150,6 +158,14 @@ public class Environment implements Seri
         this.exports.add(exports);
     }
 
+    public void removeExportPackages(Collection<String> exports) {
+        this.exports.removeAll(exports);
+    }
+
+    public void removeExportPackage(String exports) {
+        this.exports.remove(exports);
+    }
+
     public List<String> getExportPackages() {
         return Collections.unmodifiableList(new ArrayList<String>(exports));
     }
@@ -170,6 +186,14 @@ public class Environment implements Seri
         this.requireBundles.add(symbolicName);
     }
 
+    public void removeRequireBundles(Collection<String> symbolicNames) {
+        this.requireBundles.removeAll(symbolicNames);
+    }
+
+    public void removeRequireBundle(String symbolicName) {
+        this.requireBundles.remove(symbolicName);
+    }
+
     public List<String> getRequireBundles() {
         return Collections.unmodifiableList(new ArrayList<String>(requireBundles));
     }
@@ -182,10 +206,26 @@ public class Environment implements Seri
         this.dynamicImports.add(imports);
     }
 
+    public void removeDynamicImportPackages(Collection<String> imports) {
+        this.dynamicImports.removeAll(imports);
+    }
+
+    public void removeDynamicImportPackage(String imports) {
+        this.dynamicImports.remove(imports);
+    }
+
     public List<String> getDynamicImportPackages() {
         return Collections.unmodifiableList(new ArrayList<String>(dynamicImports));
     }
-    
+
+    public void removeImportPackage(String importPackage) {
+        this.imports.remove(importPackage);
+    }
+
+    public void removeImportPackages(Collection<String> importPackages) {
+        this.imports.removeAll(importPackages);
+    }
+
     public Manifest getManifest() throws ManifestException {
         Manifest manifest = new Manifest();
         manifest.addConfiguredAttribute(new Manifest.Attribute(Constants.BUNDLE_MANIFESTVERSION, "2"));
@@ -204,11 +244,11 @@ public class Environment implements Seri
         if (!imports.isEmpty()) {
             manifest.addConfiguredAttribute(new Manifest.Attribute(Manifest.Attribute.Separator.COMMA, Constants.IMPORT_PACKAGE, imports));
         }
-        
+
         if (!exports.isEmpty()) {
             manifest.addConfiguredAttribute(new Manifest.Attribute(Manifest.Attribute.Separator.COMMA, Constants.EXPORT_PACKAGE, exports));
         }
-        
+
         if (!dynamicImports.isEmpty()) {
             manifest.addConfiguredAttribute(new Manifest.Attribute(Manifest.Attribute.Separator.COMMA, Constants.DYNAMICIMPORT_PACKAGE, dynamicImports));
         }

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java Fri Jan 21 05:10:17 2011
@@ -19,6 +19,7 @@
 
 package org.apache.geronimo.system.configuration;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -41,6 +42,7 @@ import org.apache.geronimo.gbean.annotat
 import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
+import org.apache.geronimo.kernel.repository.AbstractRepository;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.ArtifactResolver;
 import org.apache.geronimo.kernel.repository.MissingDependencyException;
@@ -69,34 +71,40 @@ import org.slf4j.LoggerFactory;
 @GBean
 @OsgiService
 public class DependencyManager implements SynchronousBundleListener {
+
     private static final Logger log = LoggerFactory.getLogger(DependencyManager.class);
 
     private final BundleContext bundleContext;
+
     private final Collection<Repository> repositories;
 
     private final RepositoryAdmin repositoryAdmin;
 
     private final ArtifactResolver artifactResolver;
 
-    private final Map<Long, PluginArtifactType> pluginMap =
-            Collections.synchronizedMap(new WeakHashMap<Long, PluginArtifactType>());
+    private final Map<Long, PluginArtifactType> pluginMap = Collections.synchronizedMap(new WeakHashMap<Long, PluginArtifactType>());
 
     private final Map<Long, Set<Long>> dependentBundleIdsMap = new ConcurrentHashMap<Long, Set<Long>>();
-    private final Map<Long, Set<ExportPackage>> bundleExportPackagesMap = new ConcurrentHashMap<Long, Set<ExportPackage>>();
+
+    private final Map<Long, Set<Long>> fullDependentBundleIdsMap = new ConcurrentHashMap<Long, Set<Long>>();
+
+    private final Map<Long, Set<ExportPackage>> bundleExportPackagesMap = new HashMap<Long, Set<ExportPackage>>();
+
     private final Map<Artifact, Bundle> artifactBundleMap = new ConcurrentHashMap<Artifact, Bundle>();
 
+
     public DependencyManager(@ParamSpecial(type = SpecialAttributeType.bundleContext) BundleContext bundleContext,
-                             @ParamReference(name = "Repositories", namingType = "Repository") Collection<Repository> repositories,
-                             @ParamReference(name="ArtifactResolver", namingType = "ArtifactResolver") ArtifactResolver artifactResolver) {
+            @ParamReference(name = "Repositories", namingType = "Repository") Collection<Repository> repositories,
+            @ParamReference(name = "ArtifactResolver", namingType = "ArtifactResolver") ArtifactResolver artifactResolver) {
         this.bundleContext = bundleContext;
         this.repositories = repositories;
         this.artifactResolver = artifactResolver;
         bundleContext.addBundleListener(this);
         ServiceReference ref = bundleContext.getServiceReference(RepositoryAdmin.class.getName());
-        repositoryAdmin = ref == null? null: (RepositoryAdmin) bundleContext.getService(ref);
+        repositoryAdmin = ref == null ? null : (RepositoryAdmin) bundleContext.getService(ref);
         //init installed bundles
         for (Bundle bundle : bundleContext.getBundles()) {
-            addArtifactBundleEntry(bundle);
+            installed(bundle);
         }
         //Check the car who loads me ...
         try {
@@ -118,7 +126,8 @@ public class DependencyManager implement
 
     public void bundleChanged(BundleEvent bundleEvent) {
         int eventType = bundleEvent.getType();
-        if (eventType == BundleEvent.INSTALLED) {
+        //TODO Need to optimize the codes, as we will not receive the INSTALLED event after the cache is created
+        if (eventType == BundleEvent.INSTALLED || eventType == BundleEvent.RESOLVED) {
             installed(bundleEvent.getBundle());
         } else if (eventType == BundleEvent.STARTING) {
             starting(bundleEvent.getBundle());
@@ -128,17 +137,23 @@ public class DependencyManager implement
     }
 
     public Set<ExportPackage> getExportedPackages(Bundle bundle) {
-        Set<ExportPackage> exportPackages = bundleExportPackagesMap.get(bundle.getBundleId());
-        if (exportPackages == null) {
-            exportPackages = getExportPackagesInternal(bundle);
-            bundleExportPackagesMap.put(bundle.getBundleId(), exportPackages);
+        return getExportedPackages(bundle.getBundleId());
+    }
+
+    public Set<ExportPackage> getExportedPackages(Long bundleId) {
+        synchronized (bundleExportPackagesMap) {
+            Set<ExportPackage> exportPackages = bundleExportPackagesMap.get(bundleId);
+            if (exportPackages == null) {
+                exportPackages = getExportPackagesInternal(bundleContext.getBundle(bundleId));
+                bundleExportPackagesMap.put(bundleId, exportPackages);
+            }
+            return exportPackages;
         }
-        return exportPackages;
     }
 
     public List<Bundle> getDependentBundles(Bundle bundle) {
-        Set<Long> dependentBundleIds = dependentBundleIdsMap.get(bundle.getBundleId());
-        if (dependentBundleIds == null || dependentBundleIds.size() == 0) {
+        Set<Long> dependentBundleIds = getDependentBundleIds(bundle);
+        if (dependentBundleIds.size() == 0) {
             return Collections.<Bundle> emptyList();
         }
         List<Bundle> dependentBundles = new ArrayList<Bundle>(dependentBundleIds.size());
@@ -148,8 +163,38 @@ public class DependencyManager implement
         return dependentBundles;
     }
 
+    public Set<Long> getDependentBundleIds(Bundle bundle) {
+        Set<Long> dependentBundleIds = dependentBundleIdsMap.get(bundle.getBundleId());
+        return dependentBundleIds == null ? Collections.<Long> emptySet() : new HashSet<Long>(dependentBundleIds);
+    }
+
+    public List<Bundle> getFullDependentBundles(Bundle bundle) {
+        return getFullDependentBundles(bundle.getBundleId());
+    }
+
+    public List<Bundle> getFullDependentBundles(Long bundleId) {
+        Set<Long> fullDependentBundleIds = getFullDependentBundleIds(bundleId);
+        if (fullDependentBundleIds.size() == 0) {
+            return Collections.<Bundle> emptyList();
+        }
+        List<Bundle> dependentBundles = new ArrayList<Bundle>(fullDependentBundleIds.size());
+        for (Long dependentBundleId : fullDependentBundleIds) {
+            dependentBundles.add(bundleContext.getBundle(dependentBundleId));
+        }
+        return dependentBundles;
+    }
+
+    public Set<Long> getFullDependentBundleIds(Bundle bundle) {
+        return getFullDependentBundleIds(bundle.getBundleId());
+    }
+
+    public Set<Long> getFullDependentBundleIds(Long bundleId) {
+        Set<Long> fullDependentBundleIds = fullDependentBundleIdsMap.get(bundleId);
+        return fullDependentBundleIds == null ? Collections.<Long> emptySet() : new HashSet<Long>(fullDependentBundleIds);
+    }
+
     public Bundle getBundle(Artifact artifact) {
-        if(!artifact.isResolved()) {
+        if (!artifact.isResolved()) {
             try {
                 if (artifactResolver != null) {
                     artifact = artifactResolver.resolveInClassLoader(artifact);
@@ -161,14 +206,41 @@ public class DependencyManager implement
     }
 
     public Artifact toArtifact(String installationLocation) {
-        if (installationLocation == null || !installationLocation.startsWith("mvn:")) {
+        if (installationLocation == null) {
             return null;
         }
-        String[] artifactFragments = installationLocation.substring(4).split("[/]");
-        if(artifactFragments.length < 2) {
-            return null;
+        if (installationLocation.startsWith("mvn:")) {
+            String[] artifactFragments = installationLocation.substring(4).split("[/]");
+            if (artifactFragments.length < 2) {
+                return null;
+            }
+            return new Artifact(artifactFragments[0], artifactFragments[1], artifactFragments.length > 2 ? artifactFragments[2] : "",
+                    artifactFragments.length > 3 && artifactFragments[3].length() > 0 ? artifactFragments[3] : "jar");
+        } else if(installationLocation.startsWith("reference:file://")) {
+            //TODO a better way for this ???
+            installationLocation = installationLocation.substring("reference:file://".length());
+            for (Repository repo : repositories) {
+                if (repo instanceof AbstractRepository) {
+                    File rootFile = ((AbstractRepository) repo).getRootFile();
+                    if (installationLocation.startsWith(rootFile.getAbsolutePath())) {
+                        String artifactString = installationLocation.substring(rootFile.getAbsolutePath().length());
+                        if (artifactString.startsWith(File.separator)) {
+                            artifactString = artifactString.substring(File.separator.length());
+                        }
+                        String[] filePathFragments = artifactString.split("[" + (File.separator.equals("\\") ? "\\\\" : File.separator) + "]");
+                        if (filePathFragments.length >= 4) {
+                            StringBuilder groupId = new StringBuilder(filePathFragments[0]);
+                            for (int i = 1; i <= filePathFragments.length - 4; i++) {
+                                groupId.append(".").append(filePathFragments[i]);
+                            }
+                            return new Artifact(groupId.toString(), filePathFragments[filePathFragments.length - 3], filePathFragments[filePathFragments.length - 2],
+                                    filePathFragments[filePathFragments.length - 1].substring(filePathFragments[filePathFragments.length - 1].lastIndexOf('.') + 1));
+                        }
+                    }
+                }
+            }
         }
-        return new Artifact(artifactFragments[0], artifactFragments[1], artifactFragments.length > 2 ? artifactFragments[2] : "" ,artifactFragments.length > 3 && artifactFragments[3].length() > 0 ?artifactFragments[3] : "jar" );
+        return null;
     }
 
     private void addArtifactBundleEntry(Bundle bundle) {
@@ -193,6 +265,10 @@ public class DependencyManager implement
         ServiceReference reference = null;
         try {
             reference = bundleContext.getServiceReference(PackageAdmin.class.getName());
+            if(reference == null) {
+                log.warn("No PackageAdmin service is found, fail to get export packages of " + bundle.getLocation());
+                return Collections.<ExportPackage>emptySet();
+            }
             PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(reference);
             ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(bundle);
             if (exportedPackages != null) {
@@ -200,11 +276,11 @@ public class DependencyManager implement
                 for (ExportedPackage exportedPackage : exportedPackages) {
                     Map<String, String> attributes = new HashMap<String, String>();
                     attributes.put(Constants.VERSION_ATTRIBUTE, exportedPackage.getVersion().toString());
-                    exportPackageNames.add(new ExportPackage(exportedPackage.getName(), attributes, Collections.<String, String>emptyMap()));
+                    exportPackageNames.add(new ExportPackage(exportedPackage.getName(), attributes, Collections.<String, String> emptyMap()));
                 }
                 return exportPackageNames;
             }
-            return Collections.<ExportPackage>emptySet();
+            return Collections.<ExportPackage> emptySet();
         } finally {
             if (reference != null) {
                 bundleContext.ungetService(reference);
@@ -228,7 +304,10 @@ public class DependencyManager implement
                 log.warn("Could not read geronimo metadata for bundle: " + bundle, e);
             } finally {
                 if (in != null) {
-                    try { in.close(); } catch (IOException e) {}
+                    try {
+                        in.close();
+                    } catch (IOException e) {
+                    }
                 }
             }
         } else {
@@ -276,39 +355,43 @@ public class DependencyManager implement
         return pluginArtifactType;
     }
 
-    private void installed(Bundle bundle) {
+    public void installed(Bundle bundle) {
         addArtifactBundleEntry(bundle);
         PluginArtifactType pluginArtifactType = getCachedPluginMetadata(bundle);
-        if (pluginArtifactType != null) {
-            List<DependencyType> dependencies = pluginArtifactType.getDependency();
-            Set<Long> dependentBundleIds = new HashSet<Long>();
-            try {
-                for (DependencyType dependencyType : dependencies) {
-                    if (log.isDebugEnabled()) {
-                        log.debug("Installing artifact: " + dependencyType);
-                    }
-                    Artifact artifact = dependencyType.toArtifact();
-                    if (artifactResolver != null) {
-                        artifact = artifactResolver.resolveInClassLoader(artifact);
-                    }
-                    String location = locateBundle(artifact);
-                    try {
-                        Bundle installedBundle = bundleContext.installBundle(location);
-                        if (dependentBundleIds.add(installedBundle.getBundleId())) {
-                            Set<Long> parentDependentBundleIds = dependentBundleIdsMap.get(installedBundle
-                                    .getBundleId());
-                            if (parentDependentBundleIds != null) {
-                                dependentBundleIds.addAll(parentDependentBundleIds);
-                            }
+        if (pluginArtifactType == null) {
+            return;
+        }
+        List<DependencyType> dependencies = pluginArtifactType.getDependency();
+        Set<Long> dependentBundleIds = new HashSet<Long>();
+        Set<Long> fullDependentBundleIds = new HashSet<Long>();
+        try {
+            for (DependencyType dependencyType : dependencies) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Installing artifact: " + dependencyType);
+                }
+                Artifact artifact = dependencyType.toArtifact();
+                if (artifactResolver != null) {
+                    artifact = artifactResolver.resolveInClassLoader(artifact);
+                }
+                String location = locateBundle(artifact);
+                try {
+                    Bundle installedDependentBundle = bundleContext.installBundle(location);
+                    long installedDependentBundleId = installedDependentBundle.getBundleId();
+                    dependentBundleIds.add(installedDependentBundleId);
+                    if (fullDependentBundleIds.add(installedDependentBundleId)) {
+                        Set<Long> parentDependentBundleIds = fullDependentBundleIdsMap.get(installedDependentBundleId);
+                        if (parentDependentBundleIds != null) {
+                            fullDependentBundleIds.addAll(parentDependentBundleIds);
                         }
-                    } catch (BundleException e) {
-                        log.warn("Could not install bundle for artifact: " + artifact, e);
                     }
+                } catch (BundleException e) {
+                    log.warn("Could not install bundle for artifact: " + artifact, e);
                 }
-                dependentBundleIdsMap.put(bundle.getBundleId(), dependentBundleIds);
-            } catch (Exception e) {
-                log.error("Could not install bundle dependency", e);
             }
+            fullDependentBundleIdsMap.put(bundle.getBundleId(), fullDependentBundleIds);
+            dependentBundleIdsMap.put(bundle.getBundleId(), dependentBundleIds);
+        } catch (Exception e) {
+            log.error("Could not install bundle dependency", e);
         }
     }
 
@@ -328,7 +411,7 @@ public class DependencyManager implement
                     }
                     String location = locateBundle(artifact);
                     Bundle b = bundleContext.installBundle(location);
-                    if (b.getState() != Bundle.ACTIVE) {
+                    if (b.getState() != Bundle.ACTIVE ) {
                         bundles.add(b);
                     }
                 }
@@ -350,7 +433,8 @@ public class DependencyManager implement
 
     private String locateBundle(Artifact configurationId) throws NoSuchConfigException, IOException, InvalidConfigException {
         if (System.getProperty("geronimo.build.car") == null) {
-            return "mvn:" + configurationId.getGroupId() + "/" + configurationId.getArtifactId() + "/" + configurationId.getVersion() + ("jar".equals(configurationId.getType())?  "": "/" + configurationId.getType());
+            return "mvn:" + configurationId.getGroupId() + "/" + configurationId.getArtifactId() + "/" + configurationId.getVersion()
+                    + ("jar".equals(configurationId.getType()) ? "" : "/" + configurationId.getType());
         }
         for (Repository repo : repositories) {
             if (repo.contains(configurationId)) {

Modified: geronimo/server/trunk/plugins/client/client/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/client/client/src/main/history/dependencies.xml?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/client/client/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/client/client/src/main/history/dependencies.xml Fri Jan 21 05:10:17 2011
@@ -28,6 +28,16 @@
     </dependency>
     <dependency>
         <groupId>org.apache.bval</groupId>
+        <artifactId>bval-core</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.bval</groupId>
+        <artifactId>bval-jsr303</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.bval</groupId>
         <artifactId>org.apache.bval.bundle</artifactId>
         <type>jar</type>
     </dependency>

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/test/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/test/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/test/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java (original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/test/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java Fri Jan 21 05:10:17 2011
@@ -22,8 +22,10 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.sql.Connection;
 import java.sql.Statement;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -61,7 +63,6 @@ import org.apache.geronimo.kernel.config
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.config.ConfigurationUtil;
 import org.apache.geronimo.kernel.config.KernelConfigurationManager;
-import org.apache.geronimo.kernel.config.LifecycleException;
 import org.apache.geronimo.kernel.management.State;
 import org.apache.geronimo.kernel.mock.MockConfigStore;
 import org.apache.geronimo.kernel.mock.MockRepository;
@@ -73,12 +74,16 @@ import org.apache.geronimo.kernel.reposi
 import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.ImportType;
+import org.apache.geronimo.kernel.repository.Repository;
 import org.apache.geronimo.kernel.util.FileUtils;
 import org.apache.geronimo.kernel.util.JarUtils;
+import org.apache.geronimo.system.configuration.DependencyManager;
 import org.apache.geronimo.system.serverinfo.BasicServerInfo;
 import org.apache.geronimo.testsupport.TestSupport;
 import org.apache.geronimo.transaction.wrapper.manager.GeronimoTransactionManagerGBean;
+import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.service.packageadmin.ExportedPackage;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.packageadmin.RequiredBundle;
@@ -160,7 +165,7 @@ public class ConnectorModuleBuilderTest 
                 context = configBuilder.buildConfiguration(false, configBuilder.getConfigurationID(plan, rarFile, idBuilder), plan, rarFile, Collections.singleton(configurationStore), artifactResolver, configurationStore);
                 // add the a j2ee server so the application context reference can be resolved
                 context.addGBean("geronimo", J2EEServerImpl.GBEAN_INFO);
-                // add the module validator so the connector artifacts will resolve to an instance 
+                // add the module validator so the connector artifacts will resolve to an instance
                 AbstractName abstractName = context.getNaming().createChildName(((Module)plan).getModuleName(), "ValidatorFactory", NameFactory.VALIDATOR_FACTORY);
                 GBeanData gbeanData = new GBeanData(abstractName, ValidatorFactoryGBean.class);
                 context.addGBean(gbeanData);
@@ -199,8 +204,8 @@ public class ConnectorModuleBuilderTest 
             executeTestBuildModule(action, true);
             fail("ConstraintViolation not thrown");
         } catch (org.apache.geronimo.kernel.config.LifecycleException e) {
-            // we'll get a deployment failure.  The root reason will be a ValidationException, 
-            // but for now, that's difficult to root out and locate. 
+            // we'll get a deployment failure.  The root reason will be a ValidationException,
+            // but for now, that's difficult to root out and locate.
         }
     }
 
@@ -214,8 +219,8 @@ public class ConnectorModuleBuilderTest 
             executeTestBuildModule(action, true);
             fail("ConstraintViolation not thrown");
         } catch (org.apache.geronimo.kernel.config.LifecycleException e) {
-            // we'll get a deployment failure.  The root reason will be a ValidationException, 
-            // but for now, that's difficult to root out and locate. 
+            // we'll get a deployment failure.  The root reason will be a ValidationException,
+            // but for now, that's difficult to root out and locate.
         }
     }
 
@@ -229,12 +234,12 @@ public class ConnectorModuleBuilderTest 
             executeTestBuildModule(action, true);
             fail("ConstraintViolation not thrown");
         } catch (org.apache.geronimo.kernel.config.LifecycleException e) {
-            // we'll get a deployment failure.  The root reason will be a ValidationException, 
-            // but for now, that's difficult to root out and locate. 
+            // we'll get a deployment failure.  The root reason will be a ValidationException,
+            // but for now, that's difficult to root out and locate.
         }
     }
 
-/* TODO:  figure out what the lifecycle is here so this can be processed     
+/* TODO:  figure out what the lifecycle is here so this can be processed
     public void testActivationSpecBeanValidation() throws Exception {
         InstallAction action = new InstallAction() {
             public File getRARFile() {
@@ -245,11 +250,11 @@ public class ConnectorModuleBuilderTest 
             executeTestBuildModule(action, true);
             fail("ConstraintViolation not thrown");
         } catch (org.apache.geronimo.kernel.config.LifecycleException e) {
-            // we'll get a deployment failure.  The root reason will be a ValidationException, 
-            // but for now, that's difficult to root out and locate. 
+            // we'll get a deployment failure.  The root reason will be a ValidationException,
+            // but for now, that's difficult to root out and locate.
         }
     }
- */ 
+ */
 
     public void testBuildUnpackedAltSpecDDModule() throws Exception {
         InstallAction action = new InstallAction() {
@@ -446,7 +451,7 @@ public class ConnectorModuleBuilderTest 
                 Bundle bundle = earContext.getDeploymentBundle();
                 moduleBuilder.initContext(earContext, module, bundle);
                 moduleBuilder.addGBeans(earContext, module, bundle, Collections.singleton(repository));
-                // add the module validator so the connector artifacts will resolve to an instance 
+                // add the module validator so the connector artifacts will resolve to an instance
                 AbstractName abstractName = earContext.getNaming().createChildName(module.getModuleName(), "ValidatorFactory", NameFactory.VALIDATOR_FACTORY);
                 GBeanData gbeanData = new GBeanData(abstractName, ValidatorFactoryGBean.class);
                 earContext.addGBean(gbeanData);
@@ -474,8 +479,8 @@ public class ConnectorModuleBuilderTest 
 
             // load the configuration
             configurationManager.loadConfiguration(configurationData);
-            Configuration configuration = configurationManager.getConfiguration(configurationId);
             configurationManager.startConfiguration(configurationId);
+            Configuration configuration = configurationManager.getConfiguration(configurationId);
             Set<AbstractName> gb = configuration.getGBeans().keySet();
             for (AbstractName name : gb) {
                 if (State.RUNNING_INDEX != kernel.getGBeanState(name)) {
@@ -665,6 +670,7 @@ public class ConnectorModuleBuilderTest 
                 }
             };
         bundleContext.registerService(PackageAdmin.class.getName(), packageAdmin, null);
+        bundleContext.registerService(DependencyManager.class.getName(), new MockDependencyManager(bundleContext, Collections.<Repository> emptyList(), null), new Hashtable());
         kernel = KernelFactory.newInstance(bundleContext).createKernel("test");
         kernel.boot();
 
@@ -726,7 +732,7 @@ public class ConnectorModuleBuilderTest 
 
     protected void tearDown() throws Exception {
         kernel.shutdown();
-        ((MockConfigStore)configurationStore).cleanup(); 
+        ((MockConfigStore)configurationStore).cleanup();
         super.tearDown();
     }
 
@@ -746,4 +752,26 @@ public class ConnectorModuleBuilderTest 
         }
     }
 
+    private class MockDependencyManager extends DependencyManager {
+
+        public MockDependencyManager(BundleContext bundleContext, Collection<Repository> repositories, ArtifactResolver artifactResolver) {
+            super(bundleContext, repositories, artifactResolver);
+        }
+
+        @Override
+        public synchronized Set<ExportPackage> getExportedPackages(Bundle bundle) {
+           return Collections.<ExportPackage>emptySet();
+        }
+
+        @Override
+        public List<Bundle> getDependentBundles(Bundle bundle) {
+            return Collections.<Bundle>emptyList();
+        }
+
+        @Override
+        public Bundle getBundle(Artifact artifact) {
+            return null;
+        }
+
+    }
 }

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/test/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTestSupport.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/test/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTestSupport.java?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/test/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTestSupport.java (original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/test/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTestSupport.java Fri Jan 21 05:10:17 2011
@@ -20,6 +20,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.jar.JarFile;
@@ -48,8 +50,13 @@ import org.apache.geronimo.kernel.reposi
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.ImportType;
 import org.apache.geronimo.kernel.repository.ListableRepository;
+import org.apache.geronimo.kernel.repository.Repository;
 import org.apache.geronimo.kernel.util.FileUtils;
+import org.apache.geronimo.system.configuration.DependencyManager;
 import org.apache.geronimo.testsupport.TestSupport;
+import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 
 /**
  * Provides support for EAR config builder tests.
@@ -140,6 +147,7 @@ public abstract class EARConfigBuilderTe
         super.setUp();
         bundleContext = new MockBundleContext(getClass().getClassLoader(), "", new HashMap<Artifact, ConfigurationData>(), locations);
         ((MockBundleContext)bundleContext).setConfigurationManager(new MockConfigurationManager());
+        bundleContext.registerService(DependencyManager.class.getName(), new MockDependencyManager(bundleContext, Collections.<Repository> emptyList(), null), new Hashtable());
         Set<Artifact> repo = new HashSet<Artifact>();
         repo.add(Artifact.create("org.apache.geronimo.tests/test/1/car"));
         repository = new MockRepository(repo);
@@ -148,7 +156,7 @@ public abstract class EARConfigBuilderTe
     }
 
     protected void tearDown() throws Exception {
-        configStore.cleanup(); 
+        configStore.cleanup();
         super.tearDown();
     }
 
@@ -483,4 +491,26 @@ public abstract class EARConfigBuilderTe
         }
     }
 
+    private class MockDependencyManager extends DependencyManager {
+
+        public MockDependencyManager(BundleContext bundleContext, Collection<Repository> repositories, ArtifactResolver artifactResolver) {
+            super(bundleContext, repositories, artifactResolver);
+        }
+
+        @Override
+        public synchronized Set<ExportPackage> getExportedPackages(Bundle bundle) {
+           return Collections.<ExportPackage>emptySet();
+        }
+
+        @Override
+        public List<Bundle> getDependentBundles(Bundle bundle) {
+            return Collections.<Bundle>emptyList();
+        }
+
+        @Override
+        public Bundle getBundle(Artifact artifact) {
+            return null;
+        }
+
+    }
 }

Modified: geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/history/dependencies.xml?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/history/dependencies.xml Fri Jan 21 05:10:17 2011
@@ -76,4 +76,9 @@
         <artifactId>xbean-bundleutils</artifactId>
         <type>jar</type>
     </dependency>
+    <dependency>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>xbean-finder</artifactId>
+        <type>jar</type>
+    </dependency>
 </plugin-artifact>

Modified: geronimo/server/trunk/plugins/openejb/openejb/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/openejb/src/main/history/dependencies.xml?rev=1061636&r1=1061635&r2=1061636&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/openejb/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/openejb/openejb/src/main/history/dependencies.xml Fri Jan 21 05:10:17 2011
@@ -7,6 +7,16 @@
         <type>car</type>
     </module-id>
     <dependency>
+        <groupId>org.apache.bval</groupId>
+        <artifactId>bval-core</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.bval</groupId>
+        <artifactId>bval-jsr303</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
         <groupId>org.apache.geronimo.configs</groupId>
         <artifactId>j2ee-server</artifactId>
         <type>car</type>
@@ -137,6 +147,16 @@
         <type>jar</type>
     </dependency>
     <dependency>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>xbean-bundleutils</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>xbean-finder</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
         <groupId>org.apache.yoko</groupId>
         <artifactId>yoko-spec-corba</artifactId>
         <type>jar</type>



Mime
View raw message