Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1928 - in development/laboratory/ide: common common/magic common/magic/src common/magic/src/main common/magic/src/main/net common/magic/src/main/net/dpml common/magic/src/main/net/dpml/ide common/magic/src/main/net/dpml/ide/common common/magic/src/main/net/dpml/ide/common/magic idea-plugin idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: herzog AT raffael.ch
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1928 - in development/laboratory/ide: common common/magic common/magic/src common/magic/src/main common/magic/src/main/net common/magic/src/main/net/dpml common/magic/src/main/net/dpml/ide common/magic/src/main/net/dpml/ide/common common/magic/src/main/net/dpml/ide/common/magic idea-plugin idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic
  • Date: Wed, 02 Mar 2005 19:48:31 +0100

Author: herzog AT raffael.ch
Date: Wed Mar 2 19:48:30 2005
New Revision: 1928

Added:
development/laboratory/ide/common/
development/laboratory/ide/common/build.xml
development/laboratory/ide/common/index.xml
development/laboratory/ide/common/magic/
development/laboratory/ide/common/magic/build.xml
development/laboratory/ide/common/magic/src/
development/laboratory/ide/common/magic/src/main/
development/laboratory/ide/common/magic/src/main/net/
development/laboratory/ide/common/magic/src/main/net/dpml/
development/laboratory/ide/common/magic/src/main/net/dpml/ide/
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/

development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeDefinition.java

development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeDependency.java

development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeIndex.java

development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeProjectDefinition.java

development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeResourceDefinition.java

development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/UnresolvedDependencyException.java
development/laboratory/ide/common/module.xml
Removed:

development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/Dependency.java

development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/DependentObject.java

development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/MagicProject.java

development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/MagicResource.java
Modified:
development/laboratory/ide/idea-plugin/build.xml
development/laboratory/ide/idea-plugin/index.xml

development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/ProjectBuilder.java
Log:
Completely rewritten index.xml file parsing (using magic now) and moved the
index parser and some utilities out to ide-common. Some bugs I stumbled
across during this process fixed.

Added: development/laboratory/ide/common/build.xml
==============================================================================
--- (empty file)
+++ development/laboratory/ide/common/build.xml Wed Mar 2 19:48:30 2005
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright 2005 Raffael Herzog
+
+ 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.
+-->
+
+<project name="dpml-ide-common" default="install" basedir="."
+ xmlns:transit="antlib:net.dpml.transit">
+
+ <transit:import uri="artifact:template:dpml/magic/reactor"/>
+
+</project>

Added: development/laboratory/ide/common/index.xml
==============================================================================
--- (empty file)
+++ development/laboratory/ide/common/index.xml Wed Mar 2 19:48:30 2005
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright 2005 Raffael Herzog
+
+ 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.
+-->
+
+<index key="dpml-ide-common">
+
+ <import uri="artifact:module:dpml/transit/dpml-transit#SNAPSHOT"/>
+ <import uri="artifact:module:dpml/magic/dpml-magic#SNAPSHOT"/>
+
+ <project file="module.xml">
+ <info>
+ <group>dpml/ide</group>
+ <name>dpml-ide-common</name>
+ <version>1.0.0</version>
+ <status>SNAPSHOT</status>
+ <type>module</type>
+ </info>
+ </project>
+
+ <project basedir="magic">
+ <info>
+ <group>dpml/ide</group>
+ <name>dpml-ide-common-magic</name>
+ <version>1.0.0</version>
+ <status>SNAPSHOT</status>
+ <type>jar</type>
+ </info>
+ <dependencies>
+ <include key="commons-lang"/>
+ <include key="dpml-transit-main"/>
+ <include key="ant"/>
+ <include key="dpml-magic-core"/>
+ </dependencies>
+ </project>
+
+ <resource>
+ <info>
+ <group>commons-lang</group>
+ <name>commons-lang</name>
+ <version>2.0</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+</index>

Added: development/laboratory/ide/common/magic/build.xml
==============================================================================
--- (empty file)
+++ development/laboratory/ide/common/magic/build.xml Wed Mar 2 19:48:30
2005
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright 2005 Raffael Herzog
+
+ 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.
+-->
+
+<project name="dpml-ide-common-magic" default="install" basedir="."
+ xmlns:transit="antlib:net.dpml.transit">
+
+ <transit:import uri="artifact:template:dpml/magic/standard"/>
+
+</project>

Added:
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeDefinition.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeDefinition.java
Wed Mar 2 19:48:30 2005
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2005 Raffael Herzog
+ *
+ * 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.common.magic;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Baseclass for simplified IDE integration representations of definitions.
Definitions can be either
+ * project definitions or resource definitions.
+ *
+ * @author <a href="mailto:herzog AT raffael.ch>Raffael Herzog</a>
+ */
+public abstract class IdeDefinition {
+
+ private final String group;
+ private final String name;
+ private final String version;
+ private final Map dependencies = new HashMap();
+
+ /**
+ * Create a new definition.
+ */
+ protected IdeDefinition(String group, String name, String version) {
+ this.group = group;
+ this.name = name;
+ this.version = version;
+ }
+
+ public boolean equals(Object other) {
+ if ( other instanceof IdeDefinition ) {
+ return ((IdeDefinition)other).getName().equals(getName());
+ }
+ else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ return getName().hashCode();
+ }
+
+ public String getGroup() {
+ return group;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Determine whether this definition is a project definition.
+ *
+ * @return <code>true</code>, if it's a project definition.
+ */
+ public abstract boolean isProjectDefinition();
+
+ public void addDependency(IdeDependency dependency) {
+ dependencies.put(dependency.getKey(), dependency);
+ }
+
+ public IdeDependency removeDependency(String key) {
+ return (IdeDependency)dependencies.remove(key);
+ }
+
+ public boolean hasDependency(String key) {
+ return dependencies.containsKey(key);
+ }
+
+ public IdeDependency getDependency(String key) {
+ return (IdeDependency)dependencies.get(key);
+ }
+
+ public IdeDependency[] getDependencies() {
+ return (IdeDependency[])dependencies.values().toArray(new
IdeDependency[dependencies.size()]);
+ }
+
+}

Added:
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeDependency.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeDependency.java
Wed Mar 2 19:48:30 2005
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2005 Raffael Herzog
+ *
+ * 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.common.magic;
+
+/**
+ * A simplified representation of a project or resource dependency for IDE
integrations.
+ *
+ * @author <a href="mailto:herzog AT raffael.ch>Raffael Herzog</a>
+ */
+public class IdeDependency {
+
+ private final String key;
+ private final boolean projectDependency;
+ private boolean buildEnabled;
+ private boolean testEnabled;
+ private boolean runtimeEnabled;
+ private boolean indirect;
+
+ public IdeDependency(String key) {
+ this(key, false);
+ }
+
+ public IdeDependency(String key, boolean projectDependency) {
+ this.key = key;
+ this.projectDependency = projectDependency;
+ }
+
+ public IdeDependency(IdeDependency dep) {
+ this.key = dep.getKey();
+ this.projectDependency = dep.isProjectDependency();
+ this.buildEnabled = dep.isBuildEnabled();
+ this.testEnabled = dep.isTestEnabled();
+ this.runtimeEnabled = dep.isRuntimeEnabled();
+ this.indirect = true;
+ }
+
+ public boolean equals(Object other) {
+ if ( other instanceof IdeDependency ) {
+ return ((IdeDependency)other).getKey().equals(getKey());
+ }
+ else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ return getKey().hashCode();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public boolean isProjectDependency() {
+ return projectDependency;
+ }
+
+ public boolean isBuildEnabled() {
+ return buildEnabled;
+ }
+
+ public void setBuildEnabled(boolean buildEnabled) {
+ this.buildEnabled = buildEnabled;
+ }
+
+ public boolean isTestEnabled() {
+ return testEnabled;
+ }
+
+ public void setTestEnabled(boolean testEnabled) {
+ this.testEnabled = testEnabled;
+ }
+
+ public boolean isRuntimeEnabled() {
+ return runtimeEnabled;
+ }
+
+ public void setRuntimeEnabled(boolean runtimeEnabled) {
+ this.runtimeEnabled = runtimeEnabled;
+ }
+
+
+ /**
+ * Determine whether this is an indirect dependency (added by
+ * {@link IdeIndex#flattenProjectDependencies()}.
+ *
+ * @return <code>true</code>, if this is an indirect dependency.
+ */
+ public boolean isIndirect() {
+ return indirect;
+ }
+
+ /**
+ * Set whether this is an indirect dependency.
+ *
+ * @param indirect <code>true</code>, if the dependency is indirect.
+ */
+ public void setIndirect(boolean indirect) {
+ this.indirect = indirect;
+ }
+
+}

Added:
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeIndex.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeIndex.java
Wed Mar 2 19:48:30 2005
@@ -0,0 +1,272 @@
+/*
+ * Copyright 2005 Raffael Herzog
+ *
+ * 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.common.magic;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+import net.dpml.magic.Index;
+import net.dpml.magic.builder.IndexBuilder;
+import net.dpml.magic.model.Definition;
+import net.dpml.magic.model.ResourceRef;
+import net.dpml.magic.model.Resource;
+
+/**
+ * A simplified model of projects, resources and their dependencies.
Multiple index.xml files
+ * can be loaded into this model.
+ *
+ * @author <a href="mailto:herzog AT raffael.ch>Raffael Herzog</a>
+ */
+public class IdeIndex {
+
+ private final Map properties = new HashMap();
+ private final Map projectDefs = new HashMap();
+ private final Map resourceDefs = new HashMap();
+
+ public IdeIndex() {
+ }
+
+ /**
+ * Set a property which will be resolved by Magic.
+ *
+ * @param name The name of the property.
+ * @param value The value of the property.
+ */
+ public void setProperty(String name, String value) {
+ properties.put(name, value);
+ }
+
+ /**
+ * Get a property which will be resolved by Magic.
+ *
+ * @param name The name of the property.
+ * @return The value of the property or <code>null</code>, if the
property isn't set.
+ */
+ public String getProperty(String name) {
+ return (String)properties.get(name);
+ }
+
+ /**
+ * Get all property names.
+ *
+ * @return An array of property names.
+ */
+ public String[] getPropertyNames() {
+ return (String[])properties.keySet().toArray(new
String[properties.size()]);
+ }
+
+ /**
+ * Load an index file.
+ *
+ * @param file The index file.
+ *
+ * @throws BuildException If loading the file fails.
+ */
+ public void loadIndex(File file) throws BuildException {
+ Project antProject = new Project();
+ File parent = file.getParentFile();
+ if ( parent == null ) {
+ antProject.setBaseDir(new File("."));
+ }
+ else {
+ antProject.setBaseDir(parent);
+ }
+ Iterator props = properties.entrySet().iterator();
+ while ( props.hasNext() ) {
+ Map.Entry entry = (Map.Entry)props.next();
+ antProject.setProperty((String)entry.getKey(),
(String)entry.getValue());
+ }
+ IndexBuilder indexBuilder = new IndexBuilder(antProject, file);
+ Index index = indexBuilder.getIndex();
+ Definition[] defs = index.getDefinitions();
+ for ( int i = 0; i < defs.length; i++ ) {
+ Definition def = defs[i];
+ if ( projectDefs.containsKey(def.getInfo().getName()) ) {
+ throw new BuildException("Duplicate project definition: " +
def.getInfo().getName());
+ }
+ IdeProjectDefinition prj = new
IdeProjectDefinition(file.getParent(),
+
def.getBasePath(),
+
def.getInfo().getGroup(),
+
def.getInfo().getName(),
+
def.getInfo().getVersion());
+ ResourceRef[] parts = def.getPartRefs();
+ for ( int j = 0; j < parts.length; j++ ) {
+ ResourceRef part = parts[j];
+ IdeDependency dep = new IdeDependency(part.getKey(), true);
+ dep.setBuildEnabled(part.getPolicy().isBuildEnabled());
+ dep.setTestEnabled(part.getPolicy().isTestEnabled());
+ dep.setRuntimeEnabled(part.getPolicy().isRuntimeEnabled());
+ prj.addDependency(dep);
+ }
+ ResourceRef[] resources = def.getResourceRefs();
+ for ( int j = 0; j < resources.length; j++ ) {
+ ResourceRef resource = resources[j];
+ IdeDependency dep = new IdeDependency(resource.getKey(),
false);
+ dep.setBuildEnabled(resource.getPolicy().isBuildEnabled());
+ dep.setTestEnabled(resource.getPolicy().isTestEnabled());
+
dep.setRuntimeEnabled(resource.getPolicy().isRuntimeEnabled());
+ prj.addDependency(dep);
+ }
+ projectDefs.put(prj.getName(), prj);
+ }
+ Resource[] resources = index.getResources();
+ for ( int i = 0; i < resources.length; i++ ) {
+ Resource resource = resources[i];
+ // FIXME: do some more checking? && more types?
+ if ( resource.getInfo().getType().equals("jar") &&
!resourceDefs.containsKey(resource.getInfo().getName()) ) {
+ IdeResourceDefinition res = new
IdeResourceDefinition(index.getCacheDirectory().getPath(),
+
resource.getInfo().getPath(),
+
resource.getInfo().getType(),
+
resource.getInfo().getGroup(),
+
resource.getInfo().getName(),
+
resource.getInfo().getVersion());
+ ResourceRef[] refs = resource.getResourceRefs();
+ for ( int j = 0; j < refs.length; j++ ) {
+ ResourceRef ref = refs[j];
+ IdeDependency dep = new IdeDependency(ref.getKey(),
false);
+ dep.setBuildEnabled(ref.getPolicy().isBuildEnabled());
+ dep.setTestEnabled(ref.getPolicy().isTestEnabled());
+
dep.setRuntimeEnabled(ref.getPolicy().isRuntimeEnabled());
+ res.addDependency(dep);
+ }
+ resourceDefs.put(res.getName(), res);
+ }
+ }
+ }
+
+ /**
+ * Resolve a dependency. This method will first look for a project
definition with that name,
+ * if no project definition was found, it'll look for a resource
definition.
+ *
+ * @param key The key of the dependency
+ *
+ * @return The resolved {@link IdeDefinition} or <code>null</code>, if
the dependency could not be resolved.
+ */
+ public IdeDefinition resolve(String key) {
+ IdeDefinition def = (IdeDefinition)projectDefs.get(key);
+ if ( def == null ) {
+ def = (IdeDefinition)resourceDefs.get(key);
+ }
+ return def;
+ }
+
+ /**
+ * Filter the dependencies according to their inclusion policy.
+ *
+ * @param includeBuild Include build-time dependencies.
+ * @param includeTest Inlcude test-time dependencies.
+ * @param includeRuntime Include runtime dependencies.
+ */
+ public void filterDependencies(boolean includeBuild, boolean
includeTest, boolean includeRuntime) {
+ Iterator projects = projectDefs.values().iterator();
+ while ( projects.hasNext() ) {
+ IdeProjectDefinition project =
(IdeProjectDefinition)projects.next();
+ filterDependencies(project, includeBuild, includeTest,
includeRuntime);
+ }
+ Iterator resources = resourceDefs.values().iterator();
+ while ( resources.hasNext() ) {
+ IdeDefinition resource = (IdeDefinition)resources.next();
+ filterDependencies(resource, includeBuild, includeTest,
includeRuntime);
+ }
+ }
+
+ private void filterDependencies(IdeDefinition def, boolean includeBuild,
boolean includeTest, boolean includeRuntime) {
+ IdeDependency[] deps = def.getDependencies();
+ for ( int i = 0; i < deps.length; i++ ) {
+ IdeDependency dep = deps[i];
+ boolean include = false;
+ include |= dep.isBuildEnabled()&&includeBuild;
+ include |= dep.isTestEnabled()&&includeTest;
+ include |= dep.isRuntimeEnabled()&&includeRuntime;
+ if ( !include ) {
+ def.removeDependency(dep.getKey());
+ }
+ }
+ }
+
+ /**
+ * Flatten the dependency tree. This will iterate through all projects
and recursively add
+ * dependencies of dependencies to each project as indirect depenencies.
+ *
+ * @throws UnresolvedDependencyException Currently not thrown.
+ */
+ public void flattenProjectDependencies() throws
UnresolvedDependencyException {
+ Iterator projects = projectDefs.values().iterator();
+ while ( projects.hasNext() ) {
+ IdeProjectDefinition project =
(IdeProjectDefinition)projects.next();
+ IdeDependency[] deps = project.getDependencies();
+ Set visited = new HashSet(Arrays.asList(deps));
+ visited.add(project);
+ for ( int i = 0; i < deps.length; i++ ) {
+ IdeDependency dep = deps[i];
+ flattenProjectDependencies(project, dep, visited);
+ }
+ }
+ }
+
+ private void flattenProjectDependencies(IdeProjectDefinition root,
IdeDependency dependency, Set visited) throws UnresolvedDependencyException {
+ IdeDefinition resource = resolve(dependency.getKey());
+ if ( resource == null ) {
+ // FIXME: this doesn't look right
+ //throw new UnresolvedDependencyException(dependency.getKey());
+ return;
+ }
+ if ( !visited.contains(resource) ) {
+ visited.add(resource);
+ IdeDependency[] deps = resource.getDependencies();
+ for ( int i = 0; i < deps.length; i++ ) {
+ IdeDependency dep = deps[i];
+ IdeDependency current = root.getDependency(dep.getKey());
+ if ( current == null ) {
+ root.addDependency(new IdeDependency(dep));
+ }
+ else {
+
current.setBuildEnabled(current.isBuildEnabled()|dep.isBuildEnabled());
+
current.setTestEnabled(current.isTestEnabled()|dep.isTestEnabled());
+
current.setRuntimeEnabled(current.isRuntimeEnabled()|dep.isRuntimeEnabled());
+ }
+ flattenProjectDependencies(root, dep, visited);
+ }
+ }
+ }
+
+ /**
+ * Get all project definitions.
+ *
+ * @return An array of project definitions.
+ */
+ public IdeProjectDefinition[] getProjectDefinitions() {
+ return (IdeProjectDefinition[])projectDefs.values().toArray(new
IdeProjectDefinition[projectDefs.size()]);
+ }
+
+ /**
+ * Get all resource definitions.
+ *
+ * @return An array of resource definitions.
+ */
+ public IdeResourceDefinition[] gerResourceDefinitions() {
+ return (IdeResourceDefinition[])resourceDefs.values().toArray(new
IdeResourceDefinition[resourceDefs.size()]);
+ }
+
+}

Added:
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeProjectDefinition.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeProjectDefinition.java
Wed Mar 2 19:48:30 2005
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2005 Raffael Herzog
+ *
+ * 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.common.magic;
+
+import java.io.File;
+
+
+/**
+ * A simplified representation of a project definition for IDE integrations.
+ *
+ * @author <a href="mailto:herzog AT raffael.ch>Raffael Herzog</a>
+ */
+public class IdeProjectDefinition extends IdeDefinition {
+
+ private final String indexPath;
+ private final String basePath;
+
+ /**
+ * Create a new project definition.
+ *
+ * @param indexPath The path of the index file containing this project
definition.
+ * @param basePath The base path relative to the index file.
+ * @param group The group.
+ * @param name The name.
+ * @param version The version.
+ */
+ public IdeProjectDefinition(String indexPath, String basePath, String
group, String name, String version) {
+ super(group, name, version);
+ this.indexPath = indexPath;
+ this.basePath = basePath;
+ }
+
+ public boolean isProjectDefinition() {
+ return true;
+ }
+
+ /**
+ * Get the path of the index.xml file this project was defined in.
+ *
+ * @return The path of the index file.
+ */
+ public String getIndexPath() {
+ return indexPath;
+ }
+
+ /**
+ * Get the base path of the project relative to the index.xml file.
+ *
+ * @return The base path.
+ */
+ public String getBasePath() {
+ return basePath;
+ }
+
+ /**
+ * Get the full base path of the project.
+ *
+ * @return The full base path of the project.
+ */
+ public String getFullBasePath() {
+ return indexPath+File.separator+basePath;
+ }
+
+ public File getFullBaseFile() {
+ return new File(indexPath, basePath);
+ }
+
+}

Added:
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeResourceDefinition.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/IdeResourceDefinition.java
Wed Mar 2 19:48:30 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2005 Raffael Herzog
+ *
+ * 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.common.magic;
+
+import java.io.File;
+
+/**
+ * A simpified representation of a resource for IDE integrations.
+ * ยจ
+ * @author <a href="mailto:herzog AT raffael.ch>Raffael Herzog</a>
+ */
+public class IdeResourceDefinition extends IdeDefinition {
+
+ private final String cache;
+ private final String path;
+ private final String type;
+
+ public IdeResourceDefinition(String cache, String path, String type,
String group, String name, String version) {
+ super(group, name, version);
+ this.cache = cache;
+ this.path = path;
+ this.type = type;
+ }
+
+ public boolean isProjectDefinition() {
+ return false;
+ }
+
+ /**
+ * Get the cache directory.
+ *
+ * @return The cache directory.
+ */
+ public String getCache() {
+ return cache;
+ }
+
+ /**
+ * Get the path of this resource within the cache.
+ *
+ * @return The path of the resource.
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Get the type of the resource.
+ *
+ * @return The type of the resource.
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Get the absolute path to the resource.
+ *
+ * @return The absolute path of the resource.
+ */
+ public File getFullPath() {
+ return new File(cache, path);
+ }
+
+}

Added:
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/UnresolvedDependencyException.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/common/magic/src/main/net/dpml/ide/common/magic/UnresolvedDependencyException.java
Wed Mar 2 19:48:30 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2005 Raffael Herzog
+ *
+ * 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.common.magic;
+
+/**
+ * Exception thrown when a dependency could not be resolved.
+ *
+ * @author <a href="mailto:herzog AT raffael.ch>Raffael Herzog</a>
+ */
+public class UnresolvedDependencyException extends Exception {
+
+ /**
+ * Create a new unresolved dependency exception.
+ *
+ * @param key The key of the dependency that could not be resolved.
+ */
+ public UnresolvedDependencyException(String key) {
+ super("The dependency "+key+" could not be resolved");
+ }
+
+}

Added: development/laboratory/ide/common/module.xml
==============================================================================
--- (empty file)
+++ development/laboratory/ide/common/module.xml Wed Mar 2 19:48:30
2005
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project name="dpml-ide-common" default="install" basedir="."
+ xmlns:transit="antlib:net.dpml.transit"
+ xmlns:x="plugin:dpml/magic/dpml-magic-core">
+
+ <transit:import uri="artifact:template:dpml/magic/standard"/>
+
+ <target name="build" depends="standard.build">
+ <x:module index="index.xml">
+ <header>
+ </header>
+ </x:module>
+ </target>
+
+</project>

Modified: development/laboratory/ide/idea-plugin/build.xml
==============================================================================
--- development/laboratory/ide/idea-plugin/build.xml (original)
+++ development/laboratory/ide/idea-plugin/build.xml Wed Mar 2 19:48:30
2005
@@ -60,6 +60,12 @@
<zipfileset prefix="dpml-idea/lib"
dir="${dpml.cache}/dpml/transit/jars">
<include name="dpml-transit-main-SNAPSHOT.jar"/>
</zipfileset>
+ <zipfileset prefix="dpml-idea/lib"
dir="${dpml.cache}/dpml/magic/jars">
+ <include name="dpml-magic-core-SNAPSHOT.jar"/>
+ </zipfileset>
+ <zipfileset prefix="dpml-idea/lib"
dir="${dpml.cache}/dpml/ide/jars">
+ <include name="dpml-ide-common-magic-SNAPSHOT.jar"/>
+ </zipfileset>
</zip>
</target>


Modified: development/laboratory/ide/idea-plugin/index.xml
==============================================================================
--- development/laboratory/ide/idea-plugin/index.xml (original)
+++ development/laboratory/ide/idea-plugin/index.xml Wed Mar 2 19:48:30
2005
@@ -18,6 +18,8 @@

<index key="dpml-idea-plugin">

+ <import uri="artifact:module:dpml/ide/dpml-ide-common#SNAPSHOT"/>
+
<project basedir="magic">
<info>
<group>dpml/idea-plugin</group>
@@ -30,9 +32,12 @@
<include key="openapi" runtime="false"/>
<include key="forms_rt"/>
<include key="jdom" runtime="false"/>
+ <include key="dpml-ide-common-magic"/>
<include key="commons-lang"/>
<include key="commons-digester"/>
<include key="dpml-transit-main"/>
+ <include key="ant"/>
+ <include key="dpml-magic-core"/>
</dependencies>
</project>

@@ -125,4 +130,22 @@
</info>
</resource>

+ <resource>
+ <info>
+ <group>ant</group>
+ <name>ant</name>
+ <version>1.6.2</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>dpml/magic</group>
+ <name>dpml-magic-core</name>
+ <version>SNAPSHOT</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
</index>

Modified:
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/ProjectBuilder.java
==============================================================================
---
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/ProjectBuilder.java
(original)
+++
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/ProjectBuilder.java
Wed Mar 2 19:48:30 2005
@@ -17,11 +17,9 @@

import java.io.File;
import java.io.IOException;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -30,7 +28,6 @@
import java.util.Map;
import java.util.Set;

-import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.intellij.openapi.application.Application;
@@ -61,13 +58,15 @@
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;

-import org.apache.commons.digester.AbstractObjectCreationFactory;
-import org.apache.commons.digester.Digester;
-import org.apache.commons.digester.SetNestedPropertiesRule;
import org.apache.commons.lang.ObjectUtils;

+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 net.dpml.ide.idea.plugin.util.ExceptionPropagatingRunnable;
-import net.dpml.transit.artifact.Artifact;

/**
* The main workhorse. This object keeps the state of a project rebuild and
contains all the code.
@@ -103,28 +102,8 @@
* file in the base directory of the Magic project will be used).
*/
private final Map moduleFiles = new HashMap();
- /**
- * A set of parsed index.xml files. Used to avoid duplicate parsing due
to multiple or circular imports.
- */
- private final Set parsedFiles = new HashSet();
-
- /**
- * A map of magic projects keyed by their names.
- */
- private final Map magicProjects = new HashMap();
- /**
- * A map of magic resources keyed by their names.
- */
- private final Map magicResources = new HashMap();
- /**
- * A map of resolved dependencies (projects or resources) keyed by their
keys.
- */
- private final Map resolvedObjects = new HashMap();

- /**
- * The path of the index file currently being processed. Used by the
object factory in #{link collectDependencies(ProgressIndicator, File)}.
- */
- private String currentIndexPath;
+ private final IdeIndex index = new IdeIndex();

/**
* Create a new project builder. Each project builder can only be used
<em>once</em>!
@@ -152,8 +131,6 @@
*/
public static boolean rebuildProject(final Project project, final Logger
log, final Configuration config) {
log.info("Rebuilding project...");
- Throwable exception = null;
- final Application app = ApplicationManager.getApplication();
final ProjectBuilder builder = new ProjectBuilder(project, log,
config);
final ExceptionPropagatingRunnable rebuildRunnable =
new ExceptionPropagatingRunnable() {
@@ -161,30 +138,13 @@
Application app =
ApplicationManager.getApplication();
app.runProcessWithProgressSynchronously(this,
"Rebuilding project", true, project);
}
- protected void runImpl() {
+ protected void runImpl() throws Exception {
ProgressManager progressManager =
ProgressManager.getInstance();
ProgressIndicator progress =
progressManager.getProgressIndicator();
progress.start();
- try {
- builder.scanFiles(progress);
- builder.collectDependencies(progress);
- builder.applyDependencies(progress);
- }
- catch ( IOException exc ) {
- // will be handled below
- }
- catch ( SAXException exc ) {
- // will be handled below
- }
- catch ( UnresolvedDependencyException exc ) {
- // will be handled below
- }
- catch ( ModuleCircularDependencyException exc ) {
- // will be handled below
- }
- finally {
- progress.stop();
- }
+ builder.scanFiles(progress);
+ builder.collectDependencies(progress);
+ builder.applyDependencies(progress);
}
};
try {
@@ -194,7 +154,8 @@
return true;
}
catch ( Exception exc ) {
- Messages.showErrorDialog(project, exception.toString(), "Error");
+ Messages.showErrorDialog(project, exc.toString(), "Error");
+ log.error("Error rebuilding project", exc);
log.info("Rebuilding project finished with error.");
return false;
}
@@ -259,8 +220,8 @@
}

/**
- * Iterates through all index.xml files found by {@link
#scanFiles(ProgressIndicator)} and calls
- * {@link #collectDependencies(ProgressIndicator, File)} for each of
them.
+ * Iterates through all index.xml files found by {@link
#scanFiles(ProgressIndicator)} and loads
+ * it into the index.
*
* @param progress A progress indicator.
* @throws SAXException
@@ -277,164 +238,16 @@
while (iter.hasNext()) {
File f = (File) iter.next();
progress.setText2("Parsing file " + f + "...");
- currentIndexPath = f.getParent().toString();
- collectDependencies(progress, f);
+ index.loadIndex(f);
currentProgress += progressStep;
progress.setFraction(currentProgress);
}

+ index.filterDependencies(config.getIncludeBuildDependencies(),
+ config.getIncludeTestDependencies(),
+ config.getIncludeRuntimeDependencies());
if ( config.getRecursiveDependencies() ) {
- Iterator depIter = magicProjects.values().iterator();
- while ( depIter.hasNext() ) {
- MagicProject mp = (MagicProject)depIter.next();
- flattenDependencies(mp);
- }
- }
-
- if ( DUMP ) {
- iter = magicProjects.values().iterator();
- while (iter.hasNext()) {
- MagicProject m = (MagicProject)iter.next();
- log.info("Project: " + m.getGroup() + ":" + m.getName() + "
(" + m.getBasedir() + ")");
- Iterator iter2 = m.getDependencies().iterator();
- while (iter2.hasNext()) {
- Dependency d = (Dependency)iter2.next();
- log.info(" Dependency: "+d.getKey()+"; build:
"+d.isBuild()+"; test: "+d.isTest()+"; runtime: "+d.isRuntime());
- }
- }
- iter = magicResources.values().iterator();
- while (iter.hasNext()) {
- MagicResource r = (MagicResource)iter.next();
- log.info("Resource: " + r.getGroup() + ":" + r.getName() +
"#" + r.getVersion());
- Iterator iter2 = r.getDependencies().iterator();
- while (iter2.hasNext()) {
- Dependency d = (Dependency)iter2.next();
- log.info(" Dependency: "+d.getKey()+"; build:
"+d.isBuild()+"; test: "+d.isTest()+"; runtime: "+d.isRuntime());
- }
- }
- }
- }
-
- /**
- * Parses a specific index.xml file for dependencies of Magic projects
and resources. This method also recursively
- * calls itself, if &lt;import&gt; statements are found.
- *
- * @param progress
- * @param file
- * @throws IOException
- * @throws SAXException
- */
- private void collectDependencies(final ProgressIndicator progress, final
File file) throws IOException, SAXException {
- progress.checkCanceled();
- if ( parsedFiles.contains(file) ) {
- return;
- }
- if ( !file.isAbsolute() ) {
- throw new IOException("Absolute file path expected");
- }
- parsedFiles.add(file);
- SetNestedPropertiesRule snp;
- Digester digester = new Digester();
- digester.addFactoryCreate("index/project", new
AbstractObjectCreationFactory() {
- public Object createObject(Attributes attributes) throws
Exception {
- MagicProject prj = new MagicProject();
- prj.setIndexPath(currentIndexPath);
- return prj;
- }
- });
- digester.addSetProperties("index/project");
- snp = new SetNestedPropertiesRule();
- snp.setAllowUnknownChildElements(true);
- digester.addRule("index/project/info", snp);
- digester.addSetNext("index/project", "addMagicProject");
- digester.addObjectCreate("index/project/dependencies/include",
Dependency.class);
- digester.addSetProperties("index/project/dependencies/include");
- digester.addSetNext("index/project/dependencies/include",
"addDependency");
- // match */resource instead of index/resource for compatibility with
module files
- digester.addObjectCreate("*/resource", MagicResource.class);
- snp = new SetNestedPropertiesRule();
- snp.setAllowUnknownChildElements(true);
- digester.addRule("*/resource/info", snp);
- digester.addObjectCreate("*/resource/dependencies/include",
Dependency.class);
- digester.addSetProperties("*/resource/dependencies/include");
- digester.addSetNext("*/resource/dependencies/include",
"addDependency");
- digester.addSetNext("*/resource", "addMagicResource");
-
- digester.addFactoryCreate("*/import", new
AbstractObjectCreationFactory() {
- public Object createObject(Attributes attributes) throws
Exception {
- return new Object() {
- public void doImport(String fileName, String uri) throws
IOException, SAXException {
- if ( fileName != null ) {
- File f = new File(fileName);
- if ( !f.isAbsolute() ) {
- f = new File(file.getParent(), fileName);
- }
- collectDependencies(progress, f);
- }
- else {
- try {
- Artifact artifact =
Artifact.createArtifact(uri);
- collectDependencies(progress, new
File(config.getCacheDir(), artifact.getPath()));
- }
- catch ( URISyntaxException exc ) {
- IOException t = new IOException("Invalid URI
syntax");
- t.initCause(exc);
- throw t;
- }
-
- }
- }
- };
- }
- });
- digester.addCallMethod("*/import", "doImport", 2);
- digester.addCallParam("*/import", 0, "index");
- digester.addCallParam("*/import", 1, "uri");
- addMessage(Message.MSG_INFO, "Parsing file " + file);
- progress.setText2("Parsing file "+file);
- digester.clear();
- digester.push(new DigesterRootHooks());
- digester.parse(file);
- }
-
- /**
- * Flatten the dependencies of the given Magic project.
- *
- * @param o The Magic project
- *
- * @throws UnresolvedDependencyException
- */
- private void flattenDependencies(MagicProject o) throws
UnresolvedDependencyException {
- Set deps = new HashSet();
- flattenDependencies(o, o, deps);
- Iterator iter = deps.iterator();
- while ( iter.hasNext() ) {
- Dependency dep = (Dependency)iter.next();
- o.addDependency(dep);
- }
- }
-
- /**
- * Flatten the dependencies of a Magic project. This will recursively
descend into the dependencies of the
- * dependencies of the dependencies ... and add all of them to the root
Magic project.
- *
- * @param root The root Magic project the dependencies of which are
being flattened.
- * @param o The current dependent object (Magic project of resource).
- * @param deps A set of #{link Dependency} objects seen up to now. Used
for avoiding endless loops if there are circular dependencies.
- * @throws UnresolvedDependencyException
- */
- private void flattenDependencies(MagicProject root, DependentObject o,
Set deps) throws UnresolvedDependencyException {
- Iterator iter = o.getDependencies().iterator();
- while ( iter.hasNext() ) {
- Dependency dep = (Dependency)iter.next();
- //DependentObject d = resolve(dep.getKey());
- if ( !root.getName().equals(dep.getKey()) && !deps.contains(dep)
&& getIncludeDependency(dep) ) {
- deps.add(dep);
- //root.addDependency(dep);
- DependentObject resolved = resolve(dep.getKey());
- // FIXME: DOESN'T LOOK RIGHT
- if ( resolved != null ) flattenDependencies(root, resolved ,
deps);
- }
+ index.flattenProjectDependencies();
}
}

@@ -453,7 +266,6 @@
// IDEA module cache. Maps Magic projects to IDEA modules.
final Map modules = collectModules();

- final Application app = ApplicationManager.getApplication();
// a cache of root models; also used to commit/dispose the changes
final Set rootModels = new LinkedHashSet();
// a cache of libraries (names mapped to IDEA Library objects); also
used to commit/dispose the changes
@@ -469,7 +281,7 @@
Iterator iter = modules.entrySet().iterator();
while ( iter.hasNext() ) {
Map.Entry entry = (Map.Entry)iter.next();
- final MagicProject magicProject =
(MagicProject)entry.getKey();
+ final IdeProjectDefinition project =
(IdeProjectDefinition)entry.getKey();
final Module module = (Module)entry.getValue();
progress.setText2("Setting up module " + module.getName());

@@ -478,7 +290,7 @@
protected void runImpl() throws Exception {
new WriteActionRunnable() {
protected void runImpl() throws Exception {
- setupModule(modules, rootModels, libs,
magicProject, module);
+ setupModule(modules, rootModels, libs,
project, module);
}
}.invoke();
}
@@ -515,19 +327,17 @@
* @param modules The module cache.
* @param rootModels To root model cache.
* @param libs The library cache.
- * @param magicProject The current Magic project.
+ * @param project The current Magic project.
* @param module The IDEA module.
- *
- * @throws UnresolvedDependencyException
*/
- private void setupModule(Map modules, Set rootModels, Map libs,
MagicProject magicProject, Module module) throws IOException,
UnresolvedDependencyException {
+ private void setupModule(Map modules, Set rootModels, Map libs,
IdeProjectDefinition project, Module module) throws IOException {
addMessage(Message.MSG_INFO, "Setting up module " +
module.getName());
ModuleRootManager rootManager =
ModuleRootManager.getInstance(module);
ModifiableRootModel rootModel = rootManager.getModifiableModel();
rootModels.add(rootModel);

ContentEntry[] contentEntries = rootModel.getContentEntries();
- File moduleRootFile = new File(magicProject.getIndexPath(),
magicProject.getBasedir());
+ File moduleRootFile = project.getFullBaseFile();
VirtualFile contentFile =
LocalFileSystem.getInstance().findFileByIoFile(moduleRootFile);
ContentEntry mainContent = null;
for ( int i = 0; i < contentEntries.length; i++ ) {
@@ -587,7 +397,7 @@
if ( !foundTest && testFile != null ) {
mainContent.addSourceFolder(testFile, true);
}
- String basedir = "file://"+new File(magicProject.getIndexPath(),
magicProject.getBasedir()).getCanonicalPath().replace(File.separatorChar,
'/');
+ String basedir =
project.getFullBaseFile().getCanonicalFile().toURI().toString();
rootModel.setCompilerOutputPath(basedir+"/target/classes");

rootModel.setCompilerOutputPathForTests(basedir+"/target/test-classes");

@@ -601,23 +411,20 @@

currentOrderEntries.put(((LibraryOrderEntry)orderEntries[i]).getLibrary(),
orderEntries[i]);
}
}
- Iterator deps = magicProject.getDependencies().iterator();
- while ( deps.hasNext() ) {
- Dependency d = (Dependency)deps.next();
- boolean include = getIncludeDependency(d);
- DependentObject resolved = resolve(d.getKey());
- // FIXME: doesn't look right
- if ( resolved == null ) continue;
- if ( resolved instanceof MagicProject ) {
- MagicProject projectDependency = (MagicProject)resolved;
- Module other = (Module)modules.get(projectDependency);
- if ( other == null ) {
- addMessage(Message.MSG_WARNING, "No module found for
project " + projectDependency);
- }
- else {
- if ( include ) {
+ IdeDependency[] deps = project.getDependencies();
+ for ( int i = 0; i < deps.length; i++ ) {
+ IdeDependency dep = deps[i];
+ IdeDefinition resolved = index.resolve(dep.getKey());
+ if ( resolved != null ) {
+ if ( resolved.isProjectDefinition() ) {
+ IdeProjectDefinition projectDependency =
(IdeProjectDefinition)resolved;
+ Module other = (Module)modules.get(projectDependency);
+ if ( other == null ) {
+ addMessage(Message.MSG_WARNING, "No module found for
project " + projectDependency);
+ }
+ else {
if ( !currentOrderEntries.containsKey(other) ) {
- addMessage(Message.MSG_INFO, "Adding module " +
projectDependency.getModuleName());
+ addMessage(Message.MSG_INFO, "Adding module " +
module.getName());
rootModel.addModuleOrderEntry(other);
}
else {
@@ -627,47 +434,45 @@
}
}
}
- }
- else if ( resolved instanceof MagicResource ) {
- MagicResource resource = (MagicResource)resolved;
- addMessage(Message.MSG_INFO, "Adding resource " + resource);
- String groupPath = resource.getGroup().replace('/',
File.separatorChar);
- File path = new File(config.getCacheDir(), groupPath);
- path = new File(path, resource.getType() + "s");
- path = new File(path, resource.getName() + "-" +
resource.getVersion() + "." + resource.getType());
- String libName = resource.getLibraryName();
- LibraryEntry lib = (LibraryEntry)libs.get(libName);
- boolean update = false;
- if ( lib == null ) {
- Library library = libraryModel.getLibraryByName(libName);
- if ( library == null ) {
- addMessage(Message.MSG_INFO, "Creating library " +
libName);
- library = libraryModel.createLibrary(libName);
+ else {
+ IdeResourceDefinition resource =
(IdeResourceDefinition)resolved;
+ addMessage(Message.MSG_INFO, "Adding resource " +
resource.getName());
+ File path = resource.getFullPath();
+ String libName = resource.getGroup().replace('/', '.')
+ + "." + resource.getName()
+ + "." + resource.getType()
+ + "#" + resource.getVersion();
+ LibraryEntry lib = (LibraryEntry)libs.get(libName);
+ boolean update = false;
+ if ( lib == null ) {
+ Library library =
libraryModel.getLibraryByName(libName);
+ if ( library == null ) {
+ addMessage(Message.MSG_INFO, "Creating library "
+ libName);
+ library = libraryModel.createLibrary(libName);
+ }
+ lib = new LibraryEntry(library);
+ libs.put(libName, lib);
+ update = true;
}
- lib = new LibraryEntry(library);
- libs.put(libName, lib);
- update = true;
- }
- if ( update ) {
- addMessage(Message.MSG_INFO, "Updating library " +
libName);
- String url = "jar://" + path + "!/";
- String[] libRoots =
lib.model.getUrls(OrderRootType.CLASSES);
- boolean foundRoot = false;
- for ( int i = 0; i < libRoots.length; i++ ) {
- if ( libRoots[i].equals(url) ) {
- foundRoot = true;
- }
- else if ( config.getStrictSyncing() ) {
- addMessage(Message.MSG_INFO, "Removing library
root " + libRoots[i]);
- lib.model.removeRoot(libRoots[i],
OrderRootType.CLASSES);
+ if ( update ) {
+ addMessage(Message.MSG_INFO, "Updating library " +
libName);
+ String url = "jar://" + path + "!/";
+ String[] libRoots =
lib.model.getUrls(OrderRootType.CLASSES);
+ boolean foundRoot = false;
+ for ( int j = 0; j < libRoots.length; j++ ) {
+ if ( libRoots[j].equals(url) ) {
+ foundRoot = true;
+ }
+ else if ( config.getStrictSyncing() ) {
+ addMessage(Message.MSG_INFO, "Removing
library root " + libRoots[i]);
+ lib.model.removeRoot(libRoots[i],
OrderRootType.CLASSES);
+ }
+ }
+ if ( !foundRoot ) {
+ addMessage(Message.MSG_INFO, "Adding root " +
url + " to library " + libName);
+ lib.model.addRoot(url, OrderRootType.CLASSES);
}
}
- if ( !foundRoot ) {
- addMessage(Message.MSG_INFO, "Adding root " + url +
" to library " + libName);
- lib.model.addRoot(url, OrderRootType.CLASSES);
- }
- }
- if ( include ) {
if ( !currentOrderEntries.containsKey(lib.lib) ) {
rootModel.addLibraryEntry(lib.lib);
}
@@ -678,10 +483,6 @@
}
}
}
- else {
- addMessage(Message.MSG_ERROR, "Invalid DependentObject
instance: " + resolved);
- throw new IllegalStateException("Invalid DependentObject
instance: " + resolved);
- }
}

if ( config.getJUnitLibrary() != null ) {
@@ -725,12 +526,12 @@
private Map collectModules() throws IOException {
Map modules = new HashMap();
ProjectRootManager projectRootManager =
ProjectRootManager.getInstance(project);
- Iterator iter = magicProjects.values().iterator();
- while ( iter.hasNext() ) {
- MagicProject magicProject = (MagicProject)iter.next();
- addMessage(Message.MSG_INFO, "Checking project " + magicProject);
+ IdeProjectDefinition[] projects = index.getProjectDefinitions();
+ for ( int i = 0; i < projects.length; i++ ) {
+ IdeProjectDefinition project = projects[i];
+ addMessage(Message.MSG_INFO, "Checking project " +
project.getName());
Module module = null;
- String basedir = new File(magicProject.getIndexPath(),
magicProject.getBasedir()).getCanonicalPath();
+ String basedir = project.getFullBaseFile().getCanonicalPath();
File moduleFile = (File)moduleFiles.get(basedir);
if ( moduleFile == null ) {
addMessage(Message.MSG_WARNING, "No IDEA module found in
directory " + basedir);
@@ -743,48 +544,14 @@
addMessage(Message.MSG_WARNING, "Module " + moduleFile + "
is not in the project");
}
else {
- addMessage(Message.MSG_INFO, "Project " + magicProject +
"associated with module " + module.getName());
- modules.put(magicProject, module);
+ addMessage(Message.MSG_INFO, "Project " + project +
"associated with module " + module.getName());
+ modules.put(project, module);
}
}
return modules;
}

/**
- * Resolve a dependency.
- *
- * @param key The key of the dependency
- *
- * @return The resolved Magic project or resource or <code>null</code>,
if the dependency could not be resolved.
- *
- * @throws UnresolvedDependencyException Currently not thrown.
- */
- private DependentObject resolve(String key) throws
UnresolvedDependencyException {
- DependentObject o = (DependentObject)resolvedObjects.get(key);
- if ( o == null ) {
- o = (MagicProject)magicProjects.get(key);
- if ( o == null ) {
- o = (MagicResource)magicResources.get(key);
- }
- }
- if ( o == null ) {
- // FIXME: DOESN'T LOOK RIGHT
- addMessage(Message.MSG_WARNING, "Cannot resolve dependency with
key " + key);
- return null;
- //throw new UnresolvedDependencyException("Cannot resolve
dependency with key " + key);
- }
- else {
- return o;
- }
- }
-
- private boolean getIncludeDependency(Dependency dep) {
- return (config.getIncludeBuildDependencies() && dep.isBuild())
- || (config.getIncludeTestDependencies() && dep.isTest())
- || (config.getIncludeRuntimeDependencies() &&
dep.isRuntime());
- }
-
- /**
* Cleanup the project rebuild, i.e. commit or dispose all root/library
models.
*
* @param success If <code>true</code>, commit, else dispose.
@@ -925,21 +692,6 @@
}
}

- public final static class UnresolvedDependencyException extends
Exception {
- public UnresolvedDependencyException() {
- super();
- }
- public UnresolvedDependencyException(String message) {
- super(message);
- }
- public UnresolvedDependencyException(Throwable cause) {
- super(cause);
- }
- public UnresolvedDependencyException(String message, Throwable
cause) {
- super(message, cause);
- }
- }
-
private static abstract class InvokeAndWaitRunnable extends
ExceptionPropagatingRunnable {
public void invokeImpl() {
ApplicationManager.getApplication().invokeAndWait(this,
ModalityState.defaultModalityState());
@@ -952,23 +704,4 @@
}
}

- private final class DigesterRootHooks {
- /**
- * Called by the digester to add a new Magic project.
- *
- * @param project The new Magic project.
- */
- public void addMagicProject(MagicProject project) {
- magicProjects.put(project.getName(), project);
- }
- /**
- * Called by the digester to add a new Magic resource.
- *
- * @param resource The new Magic resource.
- */
- public void addMagicResource(MagicResource resource) {
- magicResources.put(resource.getName(), resource);
- }
- }
-
}



  • svn commit: r1928 - in development/laboratory/ide: common common/magic common/magic/src common/magic/src/main common/magic/src/main/net common/magic/src/main/net/dpml common/magic/src/main/net/dpml/ide common/magic/src/main/net/dpml/ide/common common/magic/src/main/net/dpml/ide/common/magic idea-plugin idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic, herzog, 03/02/2005

Archive powered by MHonArc 2.6.24.

Top of Page