Skip to content

Commit

Permalink
refactor: OutputType is available in Environment (#1784)
Browse files Browse the repository at this point in the history
  • Loading branch information
surli authored and monperrus committed Dec 13, 2017
1 parent bbe2e73 commit 5ed2197
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/spoon/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,14 @@ protected void processArguments() {
environment.setShouldCompile(jsapActualArgs.getBoolean("compile"));
environment.setSelfChecks(jsapActualArgs.getBoolean("disable-model-self-checks"));

String outputString = jsapActualArgs.getString("output-type");
OutputType outputType = OutputType.fromString(outputString);
if (outputType == null) {
throw new SpoonException("Unknown output type: " + outputString);
} else {
environment.setOutputType(outputType);
}

try {
Charset charset = Charset.forName(jsapActualArgs.getString("encoding"));
environment.setEncoding(charset);
Expand Down Expand Up @@ -728,15 +736,14 @@ public void process() {

@Override
public void prettyprint() {
OutputType outputType = OutputType.fromString(jsapActualArgs.getString("output-type"));
long tstart = System.currentTimeMillis();
try {
modelBuilder.generateProcessedSourceFiles(outputType, typeFilter);
modelBuilder.generateProcessedSourceFiles(getEnvironment().getOutputType(), typeFilter);
} catch (Exception e) {
throw new SpoonException(e);
}

if (!outputType.equals(OutputType.NO_OUTPUT) && getEnvironment().isCopyResources()) {
if (!getEnvironment().getOutputType().equals(OutputType.NO_OUTPUT) && getEnvironment().isCopyResources()) {
for (File dirInputSource : modelBuilder.getInputSources()) {
if (dirInputSource.isDirectory()) {
final Collection<?> resources = FileUtils.listFiles(dirInputSource, RESOURCES_FILE_FILTER, ALL_DIR_FILTER);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/spoon/compiler/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package spoon.compiler;

import org.apache.log4j.Level;
import spoon.OutputType;
import spoon.processing.FileGenerator;
import spoon.processing.ProblemFixer;
import spoon.processing.ProcessingManager;
Expand Down Expand Up @@ -362,4 +363,14 @@ void report(Processor<?> processor, Level level,
* Set the encoding to use for parsing source code
*/
void setEncoding(Charset encoding);

/**
* Set the output type used for processing files
*/
void setOutputType(OutputType outputType);

/**
* Get the output type
*/
OutputType getOutputType();
}
13 changes: 13 additions & 0 deletions src/main/java/spoon/support/StandardEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import spoon.Launcher;
import spoon.OutputType;
import spoon.SpoonException;
import spoon.compiler.Environment;
import spoon.compiler.InvalidClassPathException;
Expand Down Expand Up @@ -96,6 +97,8 @@ public class StandardEnvironment implements Serializable, Environment {

private File sourceOutputDirectory = new File(Launcher.OUTPUTDIR);

private OutputType outputType = OutputType.CLASSES;

/**
* Creates a new environment with a <code>null</code> default file
* generator.
Expand Down Expand Up @@ -540,4 +543,14 @@ public Charset getEncoding() {
public void setEncoding(Charset encoding) {
this.encoding = encoding;
}

@Override
public void setOutputType(OutputType outputType) {
this.outputType = outputType;
}

@Override
public OutputType getOutputType() {
return this.outputType;
}
}

0 comments on commit 5ed2197

Please sign in to comment.