Skip to content

Commit

Permalink
Some changes to verbose handling because the run tool now uses the st…
Browse files Browse the repository at this point in the history
…andard ceylon tool base class, so it inherits the default "verbose" option implementation (ceylon/ceylon-runtime#26)
  • Loading branch information
quintesse committed Oct 2, 2013
1 parent e3d14c6 commit 63cd5a9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
30 changes: 26 additions & 4 deletions src/main/java/com/redhat/ceylon/compiler/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

Expand All @@ -21,7 +22,7 @@ public class Options {
private boolean modulify = true;
private boolean indent = true;
private boolean comment = true;
private boolean verbose;
private String verbose;
private boolean profile;
private boolean help;
private boolean version;
Expand All @@ -32,7 +33,7 @@ public class Options {

public Options(List<String> repositories, List<String> sourceDirectories, String systemRepository,
String outputRepository, final String username, final String password,
boolean protoStyle, boolean wrapModules, boolean useIndent, boolean useComments, boolean verbosity,
boolean protoStyle, boolean wrapModules, boolean useIndent, boolean useComments, String verbosity,
boolean showTimes, boolean fromStdin, boolean generateSrcArchive,
String srcEncoding, boolean offlineMode) {
repos = repositories;
Expand Down Expand Up @@ -73,7 +74,7 @@ public static Options parse(List<String> args) {
args.remove("-nocomments");
args.remove("-compact");
}
opts.verbose = findOption("-verbose", args, true);
opts.verbose = (findOption("-verbose", args, true)) ? "" : null;
opts.offline = findOption("-offline", args, true);
opts.profile = findOption("-profile", args, true);
opts.stdin = findOption("--", args, true);
Expand Down Expand Up @@ -214,7 +215,7 @@ public boolean isIndent() {
public boolean isComment() {
return comment;
}
public boolean isVerbose() {
public String getVerbose() {
return verbose;
}
public boolean isProfile() {
Expand Down Expand Up @@ -248,5 +249,26 @@ public void setGenerateSourceArchive(boolean flag) {
public boolean isGenerateSourceArchive() {
return gensrc;
}

// Returns true if --verbose or --verbose=all has been passed on the command line
public boolean isVerbose() {
return hasVerboseFlag("");
}

// Returns true if one of the argument passed matches one of the flags given to
// --verbose=... on the command line or if one of the flags is "all"
public boolean hasVerboseFlag(String flag) {
if (verbose == null) {
return false;
}
if (verbose.isEmpty()) {
return true;
}
List<String> lst = Arrays.asList(verbose.split(","));
if (lst.contains("all")) {
return true;
}
return lst.contains(flag);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class CeylonCompileJsTool extends RepoUsingTool {
private boolean modulify = true;
private boolean indent = true;
private boolean comments = false;
private boolean verbose = false;
private boolean skipSrc = false;

private String user = null;
Expand Down Expand Up @@ -115,16 +114,6 @@ public void setNoComments(boolean nocomments) {
this.comments = !nocomments;
}

public boolean isVerbose() {
return verbose;
}

@Option
@Description("Print messages while compiling")
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}

public String getUser() {
return user;
}
Expand Down Expand Up @@ -192,29 +181,29 @@ public void setModule(List<String> moduleOrFile) {
@Override
public void run() throws Exception {
final Options opts = new Options(getRepos(), getSrc(), systemRepo, getOut(), getUser(), getPass(), isOptimize(),
isModulify(), isIndent(), isComments(), isVerbose(), isProfile(), false, !skipSrc, encoding, offline);
isModulify(), isIndent(), isComments(), getVerbose(), isProfile(), false, !skipSrc, encoding, offline);
run(opts, files);
}

private static void addFilesToCompilationSet(File dir, List<String> onlyFiles, boolean verbose) {
private static void addFilesToCompilationSet(Options opts, File dir, List<String> onlyFiles) {
for (File e : dir.listFiles()) {
String n = e.getName().toLowerCase();
if (e.isFile() && (n.endsWith(".ceylon") || n.endsWith(".js"))) {
if (verbose) {
if (opts.isVerbose()) {
System.out.println("Adding to compilation set: " + e.getPath());
}
if (!onlyFiles.contains(e.getPath())) {
onlyFiles.add(e.getPath());
}
} else if (e.isDirectory()) {
addFilesToCompilationSet(e, onlyFiles, verbose);
addFilesToCompilationSet(opts, e, onlyFiles);
}
}
}

public static void run(Options opts, List<String> files) throws IOException {
final TypeChecker typeChecker;
if (opts.isVerbose()) {
if (opts.hasVerboseFlag("cmr")) {
System.out.printf("Using repositories: %s%n", opts.getRepos());
}
final RepositoryManager repoman = CeylonUtils.repoManager()
Expand Down Expand Up @@ -324,7 +313,7 @@ public boolean equals(Object obj) {
if (opts.isVerbose()) {
System.out.println("Adding to module filters: " + filedir);
}
addFilesToCompilationSet(f, onlyFiles, opts.isVerbose());
addFilesToCompilationSet(opts, f, onlyFiles);
modfilters.add(filedir);
f = null;
}
Expand Down Expand Up @@ -396,7 +385,7 @@ public boolean equals(Object obj) {
throw new CompilerErrorException(String.format("%d errors.", count));
}
t4=System.nanoTime();
if (opts.isProfile() || opts.isVerbose()) {
if (opts.isProfile() || opts.hasVerboseFlag("benchmark")) {
System.err.println("PROFILING INFORMATION");
System.err.printf("TypeChecker creation: %6d nanos%n", t1-t0);
System.err.printf("TypeChecker processing: %6d nanos%n", t2-t1);
Expand All @@ -405,5 +394,4 @@ public boolean equals(Object obj) {
System.out.println("Compilation finished.");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void testJavaDependencies() throws IOException {
final TypeChecker tc = builder.getTypeChecker();
tc.process();
final Options opts = new Options(Collections.<String>emptyList(), Collections.singletonList("src/test/resources/javadeps"),
null, "./build", null, null, false, true, false, true, false, false, false, false, "UTF-8", false);
null, "./build", null, null, false, true, false, true, null, false, false, false, "UTF-8", false);
final JsCompiler comp = new JsCompiler(tc, opts);
comp.generate();
}
Expand Down

0 comments on commit 63cd5a9

Please sign in to comment.