From 40c0d949493e14806799cb4975135998b707c9f2 Mon Sep 17 00:00:00 2001 From: acolyer Date: Tue, 16 May 2006 18:44:41 +0000 Subject: [PATCH] progress on enh 101983 (allow separate output folders for separate source folders) --- .../tools/ajbrowser/BrowserProperties.java | 4 ++ .../aspectj/ajde/OutputLocationManager.java | 47 +++++++++++++++++++ .../ajde/ProjectPropertiesAdapter.java | 6 +++ .../ajde/internal/CompilerAdapter.java | 6 +++ .../ajde/internal/OutputLocationAdapter.java | 35 ++++++++++++++ .../org/aspectj/ajde/NullIdeProperties.java | 4 ++ .../CompilationResultDestinationManager.java | 46 ++++++++++++++++++ .../internal/core/builder/AjBuildConfig.java | 10 ++++ .../internal/core/builder/AjBuildManager.java | 10 +++- .../aspectj/testing/ajde/CompileCommand.java | 5 +- .../tools/AjdeInteractionTestbed.java | 5 ++ 11 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 ajde/src/org/aspectj/ajde/OutputLocationManager.java create mode 100644 ajde/src/org/aspectj/ajde/internal/OutputLocationAdapter.java create mode 100644 org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/CompilationResultDestinationManager.java diff --git a/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserProperties.java b/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserProperties.java index 75c8169c2..286bac0d5 100644 --- a/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserProperties.java +++ b/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserProperties.java @@ -113,6 +113,10 @@ public class BrowserProperties implements ProjectPropertiesAdapter { public void setOutputPath(String path) { preferencesAdapter.setProjectPreference("build.outputpath", path); } + + public OutputLocationManager getOutputLocationManager() { + return null; + } public String getUserClasspath() { return preferencesAdapter.getProjectPreference("build.classpath"); diff --git a/ajde/src/org/aspectj/ajde/OutputLocationManager.java b/ajde/src/org/aspectj/ajde/OutputLocationManager.java new file mode 100644 index 000000000..9a8c46d5f --- /dev/null +++ b/ajde/src/org/aspectj/ajde/OutputLocationManager.java @@ -0,0 +1,47 @@ +/* ******************************************************************* + * Copyright (c) 2006 Contributors. + * 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://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.ajde; + +import java.io.File; + +/** + * Interface to be implemented by clients that wish to control the output + * folder used to write the results of compiling individual source files. + * @author adrian colyer + * + */ +public interface OutputLocationManager { + + /** + * Return the directory root under which the results of compiling the given + * source file. For example, if the source file contains the type a.b.C, and + * this method returns "target/classes" the resulting class file will be written + * to "target/classes/a/b/C.class" + * + * @param compilationUnitName the fully-qualified name of the compilation unit that has been + * compiled + * @return a File object representing the root directory under which compilation results for this + * unit should be written + */ + File getOutputLocationForClass(String compilationUnitName); + + /** + * When copying resources from source folders to output location, return the + * root directory under which the resource should be copied. + * + * @param resourceName the fully-qualified name of the resource to be copied + * @return a File object representing the root directory under which this resource + * should be copied + */ + File getOutputLocationForResource(String resourceName); + +} diff --git a/ajde/src/org/aspectj/ajde/ProjectPropertiesAdapter.java b/ajde/src/org/aspectj/ajde/ProjectPropertiesAdapter.java index 19d08e4a3..b48c062bc 100644 --- a/ajde/src/org/aspectj/ajde/ProjectPropertiesAdapter.java +++ b/ajde/src/org/aspectj/ajde/ProjectPropertiesAdapter.java @@ -44,6 +44,12 @@ public interface ProjectPropertiesAdapter { public String getClasspath(); public String getOutputPath(); + + /** + * A non-null OutputLocationManager takes precedence over getOutputPath... + * @return + */ + public OutputLocationManager getOutputLocationManager(); // public String getAjcWorkingDir(); diff --git a/ajde/src/org/aspectj/ajde/internal/CompilerAdapter.java b/ajde/src/org/aspectj/ajde/internal/CompilerAdapter.java index 47f1e32c9..9afe186a7 100644 --- a/ajde/src/org/aspectj/ajde/internal/CompilerAdapter.java +++ b/ajde/src/org/aspectj/ajde/internal/CompilerAdapter.java @@ -576,6 +576,12 @@ public class CompilerAdapter { config.setOutputJar(new File( outJar ) ); } } + + // set compilation result destination manager if not set + if (config.getCompilationResultDestinationManager() == null && + properties.getOutputLocationManager() != null) { + config.setCompilationResultDestinationManager(new OutputLocationAdapter(properties.getOutputLocationManager())); + } join(config.getSourceRoots(), properties.getSourceRoots()); join(config.getInJars(), properties.getInJars()); diff --git a/ajde/src/org/aspectj/ajde/internal/OutputLocationAdapter.java b/ajde/src/org/aspectj/ajde/internal/OutputLocationAdapter.java new file mode 100644 index 000000000..81c54b457 --- /dev/null +++ b/ajde/src/org/aspectj/ajde/internal/OutputLocationAdapter.java @@ -0,0 +1,35 @@ +/* ******************************************************************* + * Copyright (c) 2006 Contributors. + * 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://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.ajde.internal; + +import java.io.File; + +import org.aspectj.ajde.OutputLocationManager; +import org.aspectj.ajdt.internal.compiler.CompilationResultDestinationManager; + +public class OutputLocationAdapter implements CompilationResultDestinationManager { + + private OutputLocationManager locationManager; + + public OutputLocationAdapter(OutputLocationManager mgr) { + this.locationManager = mgr; + } + + public File getOutputLocationForClass(String compilationUnitName) { + return this.locationManager.getOutputLocationForClass(compilationUnitName); + } + + public File getOutputLocationForResource(String resourceName) { + return this.locationManager.getOutputLocationForResource(resourceName); + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/NullIdeProperties.java b/ajde/testsrc/org/aspectj/ajde/NullIdeProperties.java index 233933a7a..e65f9ab26 100644 --- a/ajde/testsrc/org/aspectj/ajde/NullIdeProperties.java +++ b/ajde/testsrc/org/aspectj/ajde/NullIdeProperties.java @@ -83,6 +83,10 @@ public class NullIdeProperties implements ProjectPropertiesAdapter { this.outputPath = outputPath; } + public OutputLocationManager getOutputLocationManager() { + return null; + } + public String getAjcWorkingDir() { return testProjectPath + "/ajworkingdir"; } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/CompilationResultDestinationManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/CompilationResultDestinationManager.java new file mode 100644 index 000000000..9c544594f --- /dev/null +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/CompilationResultDestinationManager.java @@ -0,0 +1,46 @@ +/* ******************************************************************* + * Copyright (c) 2006 Contributors. + * 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://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.ajdt.internal.compiler; + +import java.io.File; + +/** + * acts as a bridge from ajde's OutputLocationManager interface to the compiler internals + * @author adrian + * + */ +public interface CompilationResultDestinationManager { + + /** + * Return the directory root under which the results of compiling the given + * source file. For example, if the source file contains the type a.b.C, and + * this method returns "target/classes" the resulting class file will be written + * to "target/classes/a/b/C.class" + * + * @param compilationUnitName the fully-qualified name of the compilation unit that has been + * compiled + * @return a File object representing the root directory under which compilation results for this + * unit should be written + */ + File getOutputLocationForClass(String compilationUnitName); + + /** + * When copying resources from source folders to output location, return the + * root directory under which the resource should be copied. + * + * @param resourceName the fully-qualified name of the resource to be copied + * @return a File object representing the root directory under which this resource + * should be copied + */ + File getOutputLocationForResource(String resourceName); + +} diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java index 472180fd6..9e5f37b90 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.aspectj.ajdt.internal.compiler.CompilationResultDestinationManager; import org.aspectj.util.FileUtil; /** @@ -43,6 +44,7 @@ public class AjBuildConfig { private File outputDir; private File outputJar; private String outxmlName; + private CompilationResultDestinationManager compilationResultDestinationManager = null; private List/*File*/ sourceRoots = new ArrayList(); private List/*File*/ files = new ArrayList(); private List /*File*/ binaryFiles = new ArrayList(); // .class files in indirs... @@ -131,7 +133,15 @@ public class AjBuildConfig { public File getOutputDir() { return outputDir; } + + public CompilationResultDestinationManager getCompilationResultDestinationManager() { + return this.compilationResultDestinationManager; + } + public void setCompilationResultDestinationManager(CompilationResultDestinationManager mgr) { + this.compilationResultDestinationManager = mgr; + } + public void setFiles(List files) { this.files = files; } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index 7e6678278..a6fbe2970 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -501,8 +501,12 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc zos.write(content); zos.closeEntry(); } else { + File destDir = buildConfig.getOutputDir(); + if (buildConfig.getCompilationResultDestinationManager() != null) { + destDir = buildConfig.getCompilationResultDestinationManager().getOutputLocationForResource(srcLocation.getAbsolutePath()); + } OutputStream fos = - FileUtil.makeOutputStream(new File(buildConfig.getOutputDir(),filename)); + FileUtil.makeOutputStream(new File(destDir,filename)); fos.write(content); fos.close(); } @@ -940,6 +944,10 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc String filename) throws IOException { File destinationPath = buildConfig.getOutputDir(); + if (buildConfig.getCompilationResultDestinationManager() != null) { + destinationPath = + buildConfig.getCompilationResultDestinationManager().getOutputLocationForClass(new String(unitResult.fileName)); + } String outFile; if (destinationPath == null) { outFile = new File(filename).getName(); diff --git a/testing/src/org/aspectj/testing/ajde/CompileCommand.java b/testing/src/org/aspectj/testing/ajde/CompileCommand.java index fd69ab9de..898d88f3b 100644 --- a/testing/src/org/aspectj/testing/ajde/CompileCommand.java +++ b/testing/src/org/aspectj/testing/ajde/CompileCommand.java @@ -23,7 +23,6 @@ import org.aspectj.ajde.ui.*; import org.aspectj.ajde.ui.internal.*; import org.aspectj.ajde.ui.swing.*; import org.aspectj.asm.*; -import org.aspectj.asm.IProgramElement; import org.aspectj.bridge.*; import org.aspectj.util.FileUtil; @@ -376,6 +375,10 @@ class ProjectProperties implements ProjectPropertiesAdapter { public void setOutJar(String input){ outJar = input; } public String getOutJar() { return outJar; } public String getOutputPath() { return outputDir; } + + public OutputLocationManager getOutputLocationManager() { + return null; + } // not known if used - log any calls to it public List getBuildConfigFiles() { return logs("buildConfigFiles"); } diff --git a/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java b/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java index 38be2dd60..582d8ecc8 100644 --- a/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java +++ b/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java @@ -27,6 +27,7 @@ import org.aspectj.ajde.Ajde; import org.aspectj.ajde.BuildOptionsAdapter; import org.aspectj.ajde.BuildProgressMonitor; import org.aspectj.ajde.ErrorHandler; +import org.aspectj.ajde.OutputLocationManager; import org.aspectj.ajde.ProjectPropertiesAdapter; import org.aspectj.ajde.TaskListManager; import org.aspectj.ajdt.internal.core.builder.AbstractStateListener; @@ -480,6 +481,10 @@ public class AjdeInteractionTestbed extends TestCase { log("MyProjectProperties.getOutputPath() [returning "+dir+"]"); return dir; } + + public OutputLocationManager getOutputLocationManager() { + return null; + } public String getBootClasspath() { log("MyProjectProperties.getBootClasspath()"); -- 2.39.5