Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.equinox.p2.directorywatcher/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/Activator.java111
-rw-r--r--bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/ConfigFileListener.java132
-rw-r--r--bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/JARFileListener.java142
-rw-r--r--bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/ProvisioningListener.java197
5 files changed, 1 insertions, 584 deletions
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.directorywatcher/META-INF/MANIFEST.MF
index 85b1ed32b..f2ec50394 100644
--- a/bundles/org.eclipse.equinox.p2.directorywatcher/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.directorywatcher/META-INF/MANIFEST.MF
@@ -22,6 +22,5 @@ Import-Package: org.eclipse.equinox.internal.p2.core.helpers,
org.osgi.util.tracker;version="1.3.0"
Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,
J2SE-1.3
-Export-Package: org.eclipse.equinox.internal.p2.directorywatcher;x-internal:=true,
- org.eclipse.equinox.internal.provisional.p2.directorywatcher
+Export-Package: org.eclipse.equinox.internal.provisional.p2.directorywatcher;x-friends:="org.eclipse.equinox.p2.reconciler.dropins"
Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.3.0,4.0)"
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/Activator.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/Activator.java
deleted file mode 100644
index 9aa7e64ae..000000000
--- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/Activator.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2008 aQute, IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * aQute - initial implementation and ideas
- * IBM Corporation - initial adaptation to Equinox provisioning use
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.directorywatcher;
-
-import java.util.*;
-import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher;
-import org.osgi.framework.*;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.service.packageadmin.PackageAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * This clever little bundle watches a directory and will install any jar file
- * if finds in that directory
- */
-
-public class Activator implements BundleActivator, ManagedServiceFactory {
- static ServiceTracker packageAdminTracker;
- static ServiceTracker configAdminTracker;
-
- private static BundleContext context;
- Map watchers = null;
-
- public static BundleContext getContext() {
- return context;
- }
-
- public void start(BundleContext aContext) throws Exception {
- Activator.context = aContext;
- watchers = new HashMap();
- Hashtable props = new Hashtable();
- props.put(Constants.SERVICE_PID, getName());
- aContext.registerService(ManagedServiceFactory.class.getName(), this, props);
-
- packageAdminTracker = new ServiceTracker(aContext, PackageAdmin.class.getName(), null);
- packageAdminTracker.open();
- configAdminTracker = new ServiceTracker(aContext, ConfigurationAdmin.class.getName(), null);
- configAdminTracker.open();
-
- // Created the initial configuration
- Hashtable properties = new Hashtable();
- set(properties, DirectoryWatcher.POLL);
- set(properties, DirectoryWatcher.DIR);
- updated("initial", properties); //$NON-NLS-1$
- }
-
- private void set(Hashtable properties, String key) {
- Object o = context.getProperty(key);
- if (o == null)
- return;
- properties.put(key, o);
- }
-
- public void stop(BundleContext aContext) throws Exception {
- if (watchers == null)
- return;
- for (Iterator i = watchers.values().iterator(); i.hasNext();)
- try {
- DirectoryWatcher watcher = (DirectoryWatcher) i.next();
- watcher.stop();
- } catch (Exception e) {
- // Ignore
- }
- watchers = null;
- configAdminTracker.close();
- packageAdminTracker.close();
- }
-
- public void deleted(String pid) {
- DirectoryWatcher watcher = (DirectoryWatcher) watchers.remove(pid);
- if (watcher != null)
- watcher.stop();
- }
-
- public String getName() {
- return "equinox.p2.directorywatcher"; //$NON-NLS-1$
- }
-
- public void updated(String pid, Dictionary properties) {
- deleted(pid);
- DirectoryWatcher watcher = new DirectoryWatcher(properties, context);
- watchers.put(pid, watcher);
- watcher.addListener(new JARFileListener());
- watcher.start();
- }
-
- public static ConfigurationAdmin getConfigAdmin() {
- return (ConfigurationAdmin) Activator.configAdminTracker.getService();
- }
-
- public static PackageAdmin getPackageAdmin(int timeout) {
- if (timeout == 0)
- return (PackageAdmin) packageAdminTracker.getService();
- try {
- return (PackageAdmin) packageAdminTracker.waitForService(timeout);
- } catch (InterruptedException e) {
- return null;
- }
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/ConfigFileListener.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/ConfigFileListener.java
deleted file mode 100644
index 4851f8815..000000000
--- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/ConfigFileListener.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2008 aQute, IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * aQute - initial implementation and ideas
- * IBM Corporation - initial adaptation to Equinox provisioning use
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.directorywatcher;
-
-import java.io.*;
-import java.util.*;
-import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryChangeListener;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-
-public class ConfigFileListener extends DirectoryChangeListener {
- public final static String ALIAS_KEY = ".alias_factory_pid";
-
- private Map seenFiles = new HashMap();
-
- public boolean added(File file) {
- // load the input file into a hashtable of settings...
- Properties temp = new Properties();
- InputStream in = null;
- try {
- in = new FileInputStream(file);
- try {
- temp.load(in);
- } finally {
- in.close();
- }
- } catch (IOException e) {
- // TODO proper logging etc here
- e.printStackTrace();
- }
- Hashtable settings = new Hashtable();
- settings.putAll(temp);
-
- String pid[] = parsePid(file.getName());
- if (pid[1] != null)
- settings.put(ALIAS_KEY, pid[1]);
- Configuration config = getConfiguration(pid[0], pid[1]);
- if (config == null)
- return false;
- if (config.getBundleLocation() != null)
- config.setBundleLocation(null);
- try {
- config.update(settings);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- seenFiles.put(file, new Long(file.lastModified()));
- return true;
- }
-
- public boolean changed(File file) {
- return added(file);
- }
-
- private Configuration getConfiguration(String pid, String factoryPid) {
- ConfigurationAdmin cm = Activator.getConfigAdmin();
- if (cm == null)
- return null;
-
- try {
- if (factoryPid != null) {
- Configuration configs[] = null;
- try {
- configs = cm.listConfigurations("(" + ALIAS_KEY + "=" + factoryPid + ")");
- } catch (InvalidSyntaxException e) {
- return null;
- }
- if (configs == null || configs.length == 0)
- return cm.createFactoryConfiguration(pid, null);
- else
- return configs[0];
- } else
- return cm.getConfiguration(pid, null);
- } catch (IOException e) {
- return null;
- }
- }
-
- public boolean isInterested(File file) {
- return file.getName().endsWith("");
- }
-
- public Long getSeenFile(File file) {
- return (Long) seenFiles.get(file);
- }
-
- private String[] parsePid(String path) {
- String pid = path.substring(0, path.length() - 4);
- int n = pid.indexOf('-');
- if (n > 0) {
- String factoryPid = pid.substring(n + 1);
- pid = pid.substring(0, n);
- return new String[] {pid, factoryPid};
- } else
- return new String[] {pid, null};
- }
-
- public boolean removed(File file) {
- String pid[] = parsePid(file.getName());
- Configuration config = getConfiguration(pid[0], pid[1]);
- if (config == null)
- return false;
- try {
- config.delete();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- seenFiles.remove(file);
- return true;
- }
-
- public void startPoll() {
- // TODO Auto-generated method stub
- }
-
- public void stopPoll() {
- // TODO Auto-generated method stub
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/JARFileListener.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/JARFileListener.java
deleted file mode 100644
index 8871af048..000000000
--- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/JARFileListener.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2008 aQute, IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * aQute - initial implementation and ideas
- * IBM Corporation - initial adaptation to Equinox provisioning use
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.directorywatcher;
-
-import java.io.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryChangeListener;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-public class JARFileListener extends DirectoryChangeListener {
- private boolean refresh = false;
- private Map seenFiles = new HashMap();
-
- public boolean added(File file) {
- InputStream in;
- try {
- in = new FileInputStream(file);
- } catch (FileNotFoundException e1) {
- return false;
- }
- Bundle bundle;
- try {
- bundle = Activator.getContext().installBundle(file.getAbsolutePath(), in);
- } catch (BundleException e1) {
- return false;
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- // ignore
- }
- }
- refresh = true;
- if (!isFragment(bundle))
- try {
- bundle.start();
- } catch (BundleException e) {
- // TODO ignore for now
- }
- seenFiles.put(file, new Long(file.lastModified()));
- return true;
- }
-
- private Bundle findBundle(String location) {
- Bundle bundles[] = Activator.getContext().getBundles();
- for (int i = 0; i < bundles.length; i++) {
- Bundle bundle = bundles[i];
- if (bundle.getLocation().equals(location))
- return bundle;
- }
- return null;
- }
-
- public boolean changed(File file) {
- Bundle bundle = findBundle(file.getAbsolutePath());
- if (bundle == null)
- // This is actually a goofy condition since we think this file changed but there
- // is no bundle for it. Perhaps we found it previously but somehow failed to install
- // it previously or it was uninstalled or...
- return false;
- InputStream in;
- try {
- in = new FileInputStream(file);
- } catch (FileNotFoundException e) {
- return false;
- }
- try {
- bundle.update(in);
- } catch (BundleException e) {
- return false;
- }
- refresh = true;
- try {
- in.close();
- } catch (IOException e) {
- // ignore
- }
- seenFiles.put(file, new Long(file.lastModified()));
- return true;
- }
-
- public boolean isInterested(File file) {
- return file.getName().endsWith(".jar");
- }
-
- public boolean removed(File file) {
- Bundle bundle = findBundle(file.getAbsolutePath());
- if (bundle == null) {
- // This is actually a goofy condition since we think this file changed but there
- // is no bundle for it. Perhaps we found it previously but somehow failed to install
- // it previously or it was uninstalled or...
- // Anyway, the bundle is gone so say we were successful anyway...
- seenFiles.remove(file);
- return true;
- }
- try {
- bundle.uninstall();
- } catch (BundleException e) {
- return false;
- }
- refresh = true;
- seenFiles.remove(file);
- return true;
- }
-
- private boolean isFragment(Bundle bundle) {
- PackageAdmin packageAdmin = Activator.getPackageAdmin(10000);
- if (packageAdmin != null)
- return packageAdmin.getBundleType(bundle) == PackageAdmin.BUNDLE_TYPE_FRAGMENT;
- return false;
- }
-
- public void startPoll() {
- refresh = false;
- }
-
- public void stopPoll() {
- if (refresh) {
- PackageAdmin packageAdmin = Activator.getPackageAdmin(10000);
- if (packageAdmin != null)
- packageAdmin.refreshPackages(null);
- refresh = false;
- }
- }
-
- public Long getSeenFile(File file) {
- return (Long) seenFiles.get(file);
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/ProvisioningListener.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/ProvisioningListener.java
deleted file mode 100644
index b760f43ef..000000000
--- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/p2/directorywatcher/ProvisioningListener.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial implementation and ideas
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.directorywatcher;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.*;
-import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
-import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
-import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
-import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
-import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryChangeListener;
-import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher;
-import org.eclipse.equinox.internal.provisional.p2.metadata.generator.*;
-import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
-import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
-
-public class ProvisioningListener extends DirectoryChangeListener {
-
- // The mapping rules for in-place generation need to construct paths that are flat,
- // with no nesting structure.
- static final private String[][] INPLACE_MAPPING_RULES = { {"(& (classifier=org.eclipse.update.feature))", "${repoUrl}/features/${id}_${version}.jar"}, //$NON-NLS-1$//$NON-NLS-2$
- {"(& (classifier=osgi.bundle))", "${repoUrl}/${id}_${version}.jar"}, //$NON-NLS-1$//$NON-NLS-2$
- {"(& (classifier=binary))", "${repoUrl}/${id}_${version}"}}; //$NON-NLS-1$//$NON-NLS-2$
-
- private Set toUninstall;
- private Set toUpdate;
- private Set toInstall;
- private Set toGenerate;
- private DirectoryWatcher watcher;
- private Map seenFiles;
-
- public ProvisioningListener(DirectoryWatcher watcher) {
- this.watcher = watcher;
- seenFiles = new HashMap();
- }
-
- public boolean added(File file) {
- toInstall.add(file);
- if (file.getName().endsWith(".iu")) {
- // add the IU and artifact entries in to the repo associated with the watched dir
- // keep track of the JARs added so we can remove them from the list of JARs
- // to be run through the metadata generator
- } else if (file.getName().endsWith(".jar")) {
- // queue up this JAR to be run through the metadata generator if needed
- toGenerate.add(file);
- }
- seenFiles.put(file, new Long(file.lastModified()));
- return true;
- }
-
- public boolean changed(File file) {
- toUpdate.add(file);
- if (file.getName().endsWith(".iu")) {
- // overwrite the IU and artifact entries in to the repo associated with the watched dir
- // keep track of the JARs added so we can remove them from the list of JARs
- // to be run through the metadata generator
- } else if (file.getName().endsWith(".jar")) {
- // queue up this JAR to be run through the metadata generator
- toGenerate.add(file);
- }
- seenFiles.put(file, new Long(file.lastModified()));
- return true;
- }
-
- public boolean removed(File file) {
- toUninstall.add(file);
- if (file.getName().endsWith(".iu")) {
- // remove the IU and artifact entries in to the repo associated with the watched dir
- // keep track of the JARs added so we can remove them from the list of JARs
- // to be run through the metadata generator
- } else if (file.getName().endsWith(".jar")) {
- // figure out which IU corresponds to this JAR and remove it
- }
- seenFiles.remove(file);
- return true;
- }
-
- public boolean isInterested(File file) {
- return file.getName().endsWith(".iu") || file.getName().endsWith(".jar");
- }
-
- private void initialize() {
- toUninstall = new HashSet(3);
- toUpdate = new HashSet(3);
- toInstall = new HashSet(3);
- toGenerate = new HashSet(3);
- }
-
- public void startPoll() {
- initialize();
- }
-
- public void stopPoll() {
- processIUs();
- generate();
- // 1) add/remove/update all the IUs and artifacts in the repo as required
- // 2) generate all the IUs we need to generate. Here we have to sort out which
- // JARs are just JARs and which are artifacts that have associated IUs. Anything with
- // an IU already does not need to be generated
- // reconcile the lists to ensure that the JAR
- // 3) construct the set of operations needed and call the engine
- // 4) kick something if needed
- initialize();
- }
-
- private IGeneratorInfo getProvider(File[] locations, File destination) {
- EclipseInstallGeneratorInfoProvider provider = new EclipseInstallGeneratorInfoProvider();
- provider.initialize(null, null, null, locations, null);
- try {
- initializeMetadataRepository(provider, destination.toURL());
- initializeArtifactRepository(provider, destination.toURL());
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- provider.setPublishArtifactRepository(true);
- provider.setPublishArtifacts(false);
- provider.setMappingRules(INPLACE_MAPPING_RULES);
- return provider;
- }
-
- private void processIUs() {
- }
-
- private void generate() {
- File[] directories = watcher.getDirectories();
- // TODO this prob isn't right.
- IGeneratorInfo info = getProvider(directories, directories[0]);
- new Generator(info).generate();
- }
-
- public Long getSeenFile(File file) {
- return (Long) seenFiles.get(file);
- }
-
- private void initializeArtifactRepository(EclipseInstallGeneratorInfoProvider provider, URL location) {
- IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
- try {
- IArtifactRepository repository = manager.loadRepository(location, null);
- if (repository.isModifiable()) {
- provider.setArtifactRepository(repository);
- if (!provider.append())
- repository.removeAll();
- return;
- }
- throw new IllegalArgumentException("Artifact repository not writeable: " + location); //$NON-NLS-1$
- } catch (ProvisionException e) {
- //fall through and create a new repository
- }
- String repositoryName = location + " - artifacts"; //$NON-NLS-1$
- try {
- IArtifactRepository result = manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY);
- manager.addRepository(result.getLocation());
- provider.setArtifactRepository(result);
- } catch (ProvisionException e) {
- LogHelper.log(e);
- }
- }
-
- private void initializeMetadataRepository(EclipseInstallGeneratorInfoProvider provider, URL location) {
- IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
- try {
- IMetadataRepository repository = manager.loadRepository(location, null);
- if (repository != null) {
- if (repository.isModifiable()) {
- provider.setMetadataRepository(repository);
- if (!provider.append())
- repository.removeAll();
- return;
- }
- throw new IllegalArgumentException("Metadata repository not writeable: " + location); //$NON-NLS-1$
- }
- } catch (ProvisionException e) {
- //fall through and create a new repository
- }
- try {
- String repositoryName = location + " - metadata"; //$NON-NLS-1$
- IMetadataRepository repository = manager.createRepository(location, repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY);
- manager.addRepository(repository.getLocation());
- provider.setMetadataRepository(repository);
- } catch (ProvisionException e) {
- LogHelper.log(e);
- }
- }
-
-}

Back to the top