notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2396 - development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core
- From: peter AT neubauer.se
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2396 - development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core
- Date: Sun, 24 Apr 2005 18:43:57 -0400
Author: peter AT neubauer.se
Date: Sun Apr 24 18:43:48 2005
New Revision: 2396
Added:
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/ArtifactURLHandler.java
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/DpmlCorePlugin.java
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/IndexActionDelegate.java
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/MagicClasspathInitializer.java
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/MagicContainer.java
Log:
readding the moved plugin classes
Added:
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/ArtifactURLHandler.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/ArtifactURLHandler.java
Sun Apr 24 18:43:48 2005
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+
*******************************************************************************/
+package net.dpml.ide.eclipse.core;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URLConnection;
+
+import net.dpml.transit.artifact.Handler;
+
+import org.osgi.service.url.URLStreamHandlerService;
+import org.osgi.service.url.URLStreamHandlerSetter;
+
+/**
+ * URL handler for the "artifact" protocol
+ */
+public class ArtifactURLHandler extends Handler implements
+ URLStreamHandlerService
+{
+ public static final String PROTOCOL = "artifact";
+
+ public ArtifactURLHandler() throws IOException
+ {
+ super();
+ }
+
+ public URLConnection openConnection( URL u ) throws IOException
+ {
+ return super.openConnection( u );
+ }
+
+ public void parseURL( URLStreamHandlerSetter realHandler, URL u,
+ String spec, int start, int limit )
+ {
+ super.parseURL( u, spec, start, limit );
+ }
+
+ /**
+ * @see "java.net.URLStreamHandler.toExternalForm"
+ */
+ public String toExternalForm( URL u )
+ {
+ return super.toExternalForm( u );
+ }
+
+ /**
+ * @see "java.net.URLStreamHandler.equals(URL, URL)"
+ */
+ public boolean equals( URL u1, URL u2 )
+ {
+ return super.equals( u1, u2 );
+ }
+
+ /**
+ * @see "java.net.URLStreamHandler.getDefaultPort"
+ */
+ public int getDefaultPort()
+ {
+ return super.getDefaultPort();
+ }
+
+ /**
+ * @see "java.net.URLStreamHandler.getHostAddress"
+ */
+ public InetAddress getHostAddress( URL u )
+ {
+ return super.getHostAddress( u );
+ }
+
+ /**
+ * @see "java.net.URLStreamHandler.hashCode(URL)"
+ */
+ public int hashCode( URL u )
+ {
+ return super.hashCode( u );
+ }
+
+ /**
+ * @see "java.net.URLStreamHandler.hostsEqual"
+ */
+ public boolean hostsEqual( URL u1, URL u2 )
+ {
+ return super.hostsEqual( u1, u2 );
+ }
+
+ /**
+ * @see "java.net.URLStreamHandler.sameFile"
+ */
+ public boolean sameFile( URL u1, URL u2 )
+ {
+ return super.sameFile( u1, u2 );
+ }
+
+}
\ No newline at end of file
Added:
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/DpmlCorePlugin.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/DpmlCorePlugin.java
Sun Apr 24 18:43:48 2005
@@ -0,0 +1,205 @@
+package net.dpml.ide.eclipse.core;
+
+import java.util.Hashtable;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.ant.core.AntCorePlugin;
+import org.eclipse.ant.core.AntCorePreferences;
+import org.eclipse.ant.core.IAntClasspathEntry;
+import org.eclipse.ant.internal.core.AntClasspathEntry;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.IStartup;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.url.URLConstants;
+import org.osgi.service.url.URLStreamHandlerService;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class DpmlCorePlugin extends Plugin implements IStartup
+{
+ /**
+ * The shared instance.
+ */
+ private static DpmlCorePlugin m_PLUGIN;
+
+ /**
+ * Resource bundle.
+ */
+ private ResourceBundle m_resourceBundle;
+
+ /**
+ * number of entries we need for the DPML libs
+ */
+ private static final int MAGIC_ENTRIES_LENGTH = 3;
+
+ /**
+ * the prefix for plugin search path
+ */
+ private static final int UPDATE_PREFIX_LENGTH = 7;
+
+ /**
+ * The constructor.
+ */
+ public DpmlCorePlugin()
+ {
+ super();
+ m_PLUGIN = this;
+ }
+
+ /**
+ *
+ * @see
org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start( BundleContext context ) throws Exception
+ {
+ super.start( context );
+ //registerArtifactHandler( context );
+
+ fixAntClasspath();
+ }
+
+ /**
+ * add the Transit libs to the root ant classpath for the eclipse ant
plugin
+ * in order to get it understand transit ant tasks
+ *
+ */
+ private void fixAntClasspath()
+ {
+ IAntClasspathEntry[] transitClasspath = new
IAntClasspathEntry[MAGIC_ENTRIES_LENGTH];
+ AntCorePreferences prefs =
AntCorePlugin.getPlugin().getPreferences();
+ IAntClasspathEntry[] coreClasspath =
prefs.getDefaultAntHomeEntries();
+ IAntClasspathEntry[] newClasspath;
+ String pluginPath =
DpmlCorePlugin.getDefault().getBundle().getLocation()
+ .substring( UPDATE_PREFIX_LENGTH );
+ try
+ {
+ transitClasspath[0] = new AntClasspathEntry( pluginPath
+ + "lib/dpml-transit-main-SNAPSHOT.jar" );
+ transitClasspath[1] = new AntClasspathEntry( pluginPath
+ + "lib/dpml-transit-tools.jar" );
+ transitClasspath[2] = new AntClasspathEntry( pluginPath
+ + "lib/junit-3.8.1.jar" );
+ }
+ catch ( Exception e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ newClasspath = new AntClasspathEntry[coreClasspath.length
+ + transitClasspath.length];
+ System.arraycopy( coreClasspath, 0, newClasspath, 0,
+ coreClasspath.length );
+ System.arraycopy( transitClasspath, 0, newClasspath,
+ coreClasspath.length, transitClasspath.length );
+ prefs.setAntHomeClasspathEntries( newClasspath );
+ }
+
+ /**
+ * Register the artifact URL support as a service to the URLHandler
service
+ *
+ * @param context
+ * the context to register in
+ */
+ private void registerArtifactHandler( BundleContext context )
+ {
+ Hashtable properties = new Hashtable( 1 );
+ properties.put( URLConstants.URL_HANDLER_PROTOCOL,
+ new String[]{ArtifactURLHandler.PROTOCOL} );
+ try
+ {
+ context.registerService(
URLStreamHandlerService.class.getName(),
+ new ArtifactURLHandler(), properties
);
+
+
+ }
+ catch ( Exception e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ *
+ * @see
org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop( BundleContext context ) throws Exception
+ {
+ super.stop( context );
+ m_PLUGIN = null;
+ m_resourceBundle = null;
+ }
+
+ /**
+ * Returns the shared instance.
+ * @return the instance
+ */
+ public static DpmlCorePlugin getDefault()
+ {
+ return m_PLUGIN;
+ }
+
+ /**
+ * Returns the string from the plugin's resource bundle, or 'key' if not
+ * found.
+ */
+ public static String getResourceString( String key )
+ {
+ ResourceBundle bundle =
DpmlCorePlugin.getDefault().getResourceBundle();
+ try
+ {
+ return ( bundle != null ) ? bundle.getString( key ) : key;
+ }
+ catch ( MissingResourceException e )
+ {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the plugin's resource bundle,
+ */
+ public ResourceBundle getResourceBundle()
+ {
+ try
+ {
+ if ( m_resourceBundle == null )
+ m_resourceBundle = ResourceBundle
+ .getBundle( "transitPlugin.TransitPluginResources" );
+ }
+ catch ( MissingResourceException x )
+ {
+ m_resourceBundle = null;
+ }
+ return m_resourceBundle;
+ }
+
+ public IPreferenceStore getPreferenceStore()
+ {
+ return null;
+ }
+
+ public void earlyStartup()
+ {
+ }
+
+ public static void log( String string, int severity )
+ {
+ DpmlCorePlugin.getDefault().getLog().log(
+ new Status( Status.INFO,
DpmlCorePlugin.getDefault().getClass()
+ .getName(), 0, string, null ) );
+
+ }
+
+ public static void logInfo( String message )
+ {
+ log( message, Status.INFO );
+
+ }
+
+}
Added:
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/IndexActionDelegate.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/IndexActionDelegate.java
Sun Apr 24 18:43:48 2005
@@ -0,0 +1,224 @@
+/*
+ * Created on 2005-mar-04
+ *
+ */
+package net.dpml.ide.eclipse.core;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TreeMap;
+
+import net.dpml.ide.common.magic.IdeIndex;
+import net.dpml.ide.common.magic.IdeProjectDefinition;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.ClasspathEntry;
+import org.eclipse.jdt.internal.core.JavaProject;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.actions.SelectionListenerAction;
+import org.osgi.service.prefs.BackingStoreException;
+
+public class IndexActionDelegate extends SelectionListenerAction implements
+ IObjectActionDelegate
+{
+
+ protected IndexActionDelegate( String text )
+ {
+ super( text );
+ }
+
+ public IndexActionDelegate()
+ {
+ this( "Index Action" );
+ }
+
+ private ILog log = DpmlCorePlugin.getDefault().getLog();
+
+ private IResource mIndexFile;
+
+ private IdeIndex index;
+
+ private IProject proj;
+
+ public void setActivePart( IAction iAction, IWorkbenchPart iTargetPart )
+ {
+
+ }
+
+ public void run( IAction iAction )
+ {
+ getIndex();
+ storeNewIndex();
+ setProjetSources();
+ }
+
+ private void storeNewIndex()
+ {
+ proj = mIndexFile.getProject();
+
+ IScopeContext projectScope = new ProjectScope( proj );
+ IEclipsePreferences projectNode = projectScope
+ .getNode( "net.dpml.magic" );
+ if ( projectNode != null )
+ {
+ projectNode.put( "index.path",
mIndexFile.getProjectRelativePath()
+ .toPortableString() );
+ try
+ {
+ projectNode.flush();
+ }
+ catch ( BackingStoreException e )
+ {
+ log.log( new Status( Status.WARNING, "net.dpml.MagicPlugin",
0,
+ "Could not store new index" +
mIndexFile.getProjectRelativePath(), e ) );
+ }
+ }
+
+ }
+
+ private void getIndex()
+ {
+ try
+ {
+ String location = mIndexFile.getLocation().toOSString();
+ File absoluteIndexFile = new File( location );
+ index = new IdeIndex();
+ index.loadIndex( absoluteIndexFile );
+ }
+ catch ( NullPointerException npe )
+ {
+ log.log( new Status( Status.WARNING, "net.dpml.MagicPlugin", 0,
+ "Could not initialize MagicContainer ", npe ) );
+ }
+
+ }
+
+ public void selectionChanged( IAction iAction, ISelection iSelection )
+ {
+ if ( iSelection.isEmpty() )
+ {
+ return;
+ }
+ StructuredSelection selection = (StructuredSelection) iSelection;
+ mIndexFile = (IFile) selection.getFirstElement();
+
+
+ }
+
+ /**
+ * The <code>DeleteResourceAction</code> implementation of this
+ * <code>SelectionListenerAction</code> method disables the action if the
+ * selection contains phantom resources or non-resources
+ */
+ protected boolean updateSelection( IStructuredSelection selection )
+ {
+ return super.updateSelection( selection );
+ }
+
+ private void setProjetSources()
+ {
+ TreeMap collectedSources = new TreeMap();
+ IdeProjectDefinition[] projects = index.getProjectDefinitions();
+ for ( int i = 0; i < projects.length; i++ )
+ {
+ IdeProjectDefinition project = projects[i];
+ DpmlCorePlugin.logInfo( "Checking project " + project.getName()
);
+ collectSources( project, collectedSources );
+ }
+
+ List sourceEntries = new ArrayList();
+
+ Iterator collSources = collectedSources.values().iterator();
+ while ( collSources.hasNext() )
+ {
+ IClasspathEntry srcDir = (IClasspathEntry) collSources.next();
+ sourceEntries.add( srcDir );
+ }
+ // add the magic container
+ IClasspathEntry magicContainer = JavaCore.newContainerEntry( new
Path(
+ "net.dpml.MAGIC/deps" ) );
+ sourceEntries.add( magicContainer );
+ IClasspathEntry jreContainer = JavaCore.newContainerEntry( new Path(
+ "org.eclipse.jdt.launching.JRE_CONTAINER" ) );
+ sourceEntries.add( jreContainer );
+ IClasspathEntry[] sourcePath = (IClasspathEntry[]) sourceEntries
+ .toArray( new IClasspathEntry[sourceEntries.size()] );
+ IJavaProject javaProject = null;
+ try
+ {
+ IProjectNature nature = proj
+ .getNature( "org.eclipse.jdt.core.javanature" );
+ javaProject = (JavaProject) nature;
+ }
+ catch ( CoreException e1 )
+ {
+ log.log( new Status( Status.ERROR, "net.dpml.MagicPlugin", 0,
+ "Could not initialize MagicContainer 0", e1 ) );
+ }// = proj;
+ try
+ {
+ javaProject.setRawClasspath( sourcePath, null );
+ }
+ catch ( JavaModelException e )
+ {
+ log.log( new Status( Status.ERROR, "net.dpml.MagicPlugin", 0,
+ "Could not initialize MagicContainer 1", e ) );
+ }
+ }
+
+ private void collectSources( IdeProjectDefinition project,
+ TreeMap collectedSources )
+ {
+ IPath projectPath = new Path( project.getFullBaseDir().toString() );
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IResource fileForLocation = root.getContainerForLocation(
projectPath );
+ IPath absoluteProjectPath = fileForLocation.getFullPath();
+ IPath main = absoluteProjectPath.append( "src/main" );
+ IPath test = absoluteProjectPath.append( "src/test" );
+ IPath java = absoluteProjectPath.append( "src/java" );
+ if ( proj.exists( main.removeFirstSegments( 1 ) ) )
+ {
+ // IPath source =
+ //
proj.getFullPath().append(proj.getFile(main).getProjectRelativePath());
+ IPath out = absoluteProjectPath.append( "target/classes" );
+ collectedSources.put( main.toString(), JavaCore.newSourceEntry(
+ main, ClasspathEntry.INCLUDE_ALL, out ) );
+ }
+ if ( proj.exists( test.removeFirstSegments( 1 ) ) )
+ {
+ IPath out = absoluteProjectPath.append( "target/test-classes" );
+ collectedSources.put( test.toString(), JavaCore.newSourceEntry(
+ test, ClasspathEntry.INCLUDE_ALL, out ) );
+ }
+ if ( proj.exists( java.removeFirstSegments( 1 ) ) )
+ {
+ IPath out = absoluteProjectPath.append( "target/classes" );
+ collectedSources.put( test.toString(), JavaCore.newSourceEntry(
+ java, ClasspathEntry.INCLUDE_ALL, out ) );
+ }
+ }
+}
Added:
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/MagicClasspathInitializer.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/MagicClasspathInitializer.java
Sun Apr 24 18:43:48 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ *
+ * Licensed 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 net.dpml.ide.eclipse.core;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.ClasspathContainerInitializer;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+
+public class MagicClasspathInitializer extends ClasspathContainerInitializer
+{
+
+ private static final String MAGIC = "net.dpml.MAGIC";
+
+ public void initialize( IPath containerPath, IJavaProject project )
+ throws CoreException
+ {
+ int size = containerPath.segmentCount();
+ if ( size > 1 )
+ {
+ if ( containerPath.segment( 0 ).equals( MAGIC ) )
+ {
+ MagicContainer container = new MagicContainer( project,
+ containerPath );
+ JavaCore.setClasspathContainer( containerPath,
+ new IJavaProject[] { project },
+ new IClasspathContainer[] { container }, null );
+ }
+ }
+
+ }
+
+}
Added:
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/MagicContainer.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core/MagicContainer.java
Sun Apr 24 18:43:48 2005
@@ -0,0 +1,278 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ *
+ * Licensed 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 net.dpml.ide.eclipse.core;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TreeMap;
+
+import net.dpml.ide.common.magic.IdeDefinition;
+import net.dpml.ide.common.magic.IdeDependency;
+import net.dpml.ide.common.magic.IdeIndex;
+import net.dpml.ide.common.magic.IdeProjectDefinition;
+import net.dpml.ide.common.magic.IdeResourceDefinition;
+import net.dpml.ide.common.magic.UnresolvedDependencyException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+
+/**
+ * Serves up the dependencies from the index dynamically by populating a
+ * container
+ */
+public class MagicContainer implements IClasspathContainer
+{
+ /**
+ * the coinatiner path in case we need it
+ */
+ private IPath m_containerPath;
+
+ /**
+ * the processed index
+ */
+ private IdeIndex m_index = null;
+
+ /**
+ * Eclipse logger
+ */
+ private ILog m_log;
+
+ /**
+ * the identification id in the .classpath, the same as the plugin has
+ * registered for this handler
+ */
+ public static final String ID = "net.dpml.MAGIC";
+
+ /**
+ * the current index file
+ */
+ private IFile m_indexFile;
+
+ /**
+ * the eclipse resource project
+ */
+ private IProject m_reosurceProject;
+
+ /**
+ *
+ * @param project
+ * the eclipse project to work on
+ * @param containerPath
+ * the path of the container entry in .classpath for
validation
+ * purposes
+ */
+ public MagicContainer( IJavaProject project, IPath containerPath )
+ {
+ m_log = DpmlCorePlugin.getDefault().getLog();
+ m_log.log( new Status( Status.INFO, "net.dpml.MagicPlugin", 0,
+ "ContainerPath: " + containerPath, null ) );
+ m_log.log( new Status( Status.INFO, "net.dpml.MagicPlugin", 0,
+ "Project: " + m_reosurceProject, null ) );
+ this.m_containerPath = containerPath;
+ if ( !containerPath.segment( 0 ).equals( ID ) )
+ {
+ return;
+ }
+ m_reosurceProject = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject( project.getElementName() );
+ m_log.log( new Status( Status.INFO, "net.dpml.MagicPlugin", 0,
+ "Project: " + m_reosurceProject, null ) );
+ try
+ {
+ getIndexFile();
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ m_log
+ .log( new Status(
+ Status.ERROR,
+ "net.dpml.MagicPlugin",
+ 0,
+ "Could not load index file form the project
prefs. try reloading the magic index again to get it set.",
+ null ) );
+ return;
+
+ }
+ try
+ {
+ String location = m_indexFile.getLocation().toOSString();
+ File absoluteIndexFile = new File( location );
+ m_index = new IdeIndex();
+ m_index.loadIndex( absoluteIndexFile );
+ }
+ catch ( NullPointerException npe )
+ {
+ m_log.log( new Status( Status.WARNING,
"net.dpml.MagicPlugin",
+ 0, "Could not initialize MagicContainer ", npe ) );
+ }
+ }
+
+ /**
+ *
+ * @throws Exception
+ * the indx file could not be found (missing project prefs
for
+ * example)
+ */
+ private void getIndexFile()
+ {
+ IScopeContext projectScope = new ProjectScope( m_reosurceProject );
+ IEclipsePreferences projectNode = projectScope
+ .getNode( "net.dpml.magic" );
+ String indexPath = null;
+ if ( projectNode != null )
+ {
+ indexPath = projectNode.get( "index.path", null );
+ }
+ else
+ {
+ m_log.log( new Status( Status.ERROR, "net.dpml.MagicPlugin",
+ 0, "Could not initialize get Index file from prefs",
null) );
+
+ }
+ if ( indexPath != null )
+ {
+ m_indexFile = m_reosurceProject.getFile( new Path( indexPath ) );
+ }
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.jdt.core.IClasspathContainer#getClasspathEntries()
+ */
+ public IClasspathEntry[] getClasspathEntries()
+ {
+ getIndexFile();
+ if ( m_index == null )
+ {
+ return null;
+ }
+ try
+ {
+ m_index.flattenProjectDependencies();
+ }
+ catch ( UnresolvedDependencyException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ TreeMap collectedDeps = new TreeMap();
+ IdeProjectDefinition[] projects = m_index.getProjectDefinitions();
+ for ( int i = 0; i < projects.length; i++ )
+ {
+ IdeProjectDefinition project = projects[i];
+ IdeDependency[] deps = project.getDependencies();
+ for ( int k = 0; k < deps.length; k++ )
+ {
+ IdeDependency dep = deps[k];
+ IdeDefinition resolved = m_index.resolve( dep.getKey() );
+ File depPath = getDependencyPath( resolved );
+ if ( depPath != null )
+ {
+ collectedDeps.put( dep.getKey(), depPath );
+ }
+ }
+ }
+ List entries = new ArrayList();
+ Iterator collEntries = collectedDeps.values().iterator();
+ // for (int i = 0; i < rs.length; i++) {
+ while ( collEntries.hasNext() )
+ {
+ File dep = (File) collEntries.next();
+ entries.add( JavaCore.newLibraryEntry( new Path( dep
+ .getAbsolutePath() ), null, null ) );
+ }
+ return (IClasspathEntry[]) entries.toArray( new
IClasspathEntry[entries
+ .size()] );
+ }
+
+ /**
+ *
+ * @param dependency
+ * the dependency
+ * @return the full path in the file system
+ */
+ private File getDependencyPath( IdeDefinition dependency )
+ {
+ File resolvedPath = null;
+ if ( dependency != null )
+ {
+ if ( dependency.isProjectDefinition() )
+ {
+ }
+ else
+ {
+ IdeResourceDefinition resource = (IdeResourceDefinition)
dependency;
+ resolvedPath = resource.getFullPath();
+ }
+ }
+ return resolvedPath;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jdt.core.IClasspathContainer#getDescription()
+ */
+ public String getDescription()
+ {
+ try
+ {
+ getIndexFile();
+ }
+ catch ( Exception e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return "[" + m_indexFile + "] Magic Dependencies";
+ }
+
+ /**
+ *
+ * @see org.eclipse.jdt.core.IClasspathContainer#getKind()
+ */
+ public int getKind()
+ {
+ return IClasspathContainer.K_APPLICATION;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jdt.core.IClasspathContainer#getPath()
+ */
+ public IPath getPath()
+ {
+ return m_containerPath;
+ }
+
+}
- svn commit: r2396 - development/laboratory/ide/eclipse/plugins/net.dpml.ide.eclipse.core/src/net/dpml/ide/eclipse/core, peter, 04/24/2005
Archive powered by MHonArc 2.6.24.