Skip to content

Commit

Permalink
[sarlc] Rename "working directory" options and functions to "temp dir…
Browse files Browse the repository at this point in the history
…ectory".

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Oct 2, 2019
1 parent 7389257 commit 29a275a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 32 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -454,6 +454,11 @@
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
Expand Down
Expand Up @@ -21,6 +21,7 @@

package io.sarl.lang.sarlc.commands;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -95,14 +96,18 @@ public CommandOutcome run(Cli cli) {
final PathDetector paths = this.pathDetector.get();
paths.setSarlOutputPath(config.getOutputPath());
paths.setClassOutputPath(config.getClassOutputPath());
paths.setWorkingPath(config.getWorkingPath());
paths.resolve(cli.standaloneArguments());
paths.setTempDirectory(config.getTempDirectory());
try {
paths.resolve(cli.standaloneArguments());
} catch (IOException exception) {
return CommandOutcome.failed(BootiqueMain.ERROR_CODE, exception);
}

final SarlBatchCompiler comp = this.compiler.get();

comp.setOutputPath(paths.getSarlOutputPath());
comp.setClassOutputPath(paths.getClassOutputPath());
comp.setTempDirectory(paths.getWorkingPath());
comp.setTempDirectory(paths.getTempDirectory());

for (final String cliArg : cli.standaloneArguments()) {
comp.addSourcePath(cliArg);
Expand Down
Expand Up @@ -53,9 +53,9 @@ public class SarlcConfig {
public static final String OUTPUT_PATH_NAME = PREFIX + ".outputPath"; //$NON-NLS-1$

/**
* Name of the property that contains the working path.
* Name of the property that contains the temp directory used by the SARL compiler.
*/
public static final String WORKING_PATH_NAME = PREFIX + ".workingPath"; //$NON-NLS-1$
public static final String TEMP_DIRECTORY_NAME = PREFIX + ".tempDirectory"; //$NON-NLS-1$

/**
* Name of the property that contains the output path for the Java byte code.
Expand Down Expand Up @@ -92,7 +92,7 @@ public class SarlcConfig {

private File classOutputPath;

private File workingPath;
private File tempDirectory;

private CompilerConfig compilerConfig;

Expand Down Expand Up @@ -195,21 +195,21 @@ public void setOutputPath(File path) {
this.outputPath = path;
}

/** Replies the working path.
/** Replies the path in which the SARL compiler will write temp files.
*
* @return the working path
*/
public File getWorkingPath() {
return this.workingPath;
public File getTempDirectory() {
return this.tempDirectory;
}

/** Change the working path.
/** Change the path in which the SARL compiler will write temp files.
*
* @param path the working path.
*/
@BQConfigProperty("Working/temporary path for the SARL compiler.")
public void setWorkingPath(File path) {
this.workingPath = path;
public void setTempDirectory(File path) {
this.tempDirectory = path;
}

/** Replies the compiler configuration.
Expand Down
Expand Up @@ -27,7 +27,7 @@
import static io.sarl.lang.sarlc.configs.SarlcConfig.CLASS_OUTPUT_PATH_NAME;
import static io.sarl.lang.sarlc.configs.SarlcConfig.EXTRA_GENERATOR_NAME;
import static io.sarl.lang.sarlc.configs.SarlcConfig.OUTPUT_PATH_NAME;
import static io.sarl.lang.sarlc.configs.SarlcConfig.WORKING_PATH_NAME;
import static io.sarl.lang.sarlc.configs.SarlcConfig.TEMP_DIRECTORY_NAME;

import java.io.File;
import java.text.MessageFormat;
Expand Down Expand Up @@ -62,7 +62,7 @@ public class SarlcConfigModule extends AbstractModule {

private static final String CLASSPATH_SHORT_OPTION = "cp"; //$NON-NLS-1$

private static final String WORKING_DIR_OPTION = "workingdir"; //$NON-NLS-1$
private static final String TEMP_DIR_OPTION = "tempdir"; //$NON-NLS-1$

private static final String BOOTCLASSPATH_OPTION = "bootclasspath"; //$NON-NLS-1$

Expand Down Expand Up @@ -90,12 +90,12 @@ protected void configure() {
.build())
.mapConfigPath(Constants.JAVA_OUTPUT_DIRECTORY_OPTION, CLASS_OUTPUT_PATH_NAME);

VariableDecls.extend(binder()).declareVar(WORKING_PATH_NAME);
VariableDecls.extend(binder()).declareVar(TEMP_DIRECTORY_NAME);
extend(binder()).addOption(OptionMetadata.builder(
WORKING_DIR_OPTION, Messages.SarlcConfigModule_2)
TEMP_DIR_OPTION, Messages.SarlcConfigModule_2)
.valueRequired(Messages.SarlcConfigModule_1)
.build())
.mapConfigPath(WORKING_DIR_OPTION, WORKING_PATH_NAME);
.mapConfigPath(TEMP_DIR_OPTION, TEMP_DIRECTORY_NAME);

VariableDecls.extend(binder()).declareVar(CLASSPATH_NAME);
final String cpDescription = MessageFormat.format(Messages.SarlcConfigModule_3,
Expand Down
Expand Up @@ -22,6 +22,7 @@
package io.sarl.lang.sarlc.tools;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.LinkedList;
Expand All @@ -47,7 +48,7 @@ public class DefaultPathDetector implements PathDetector {

private File classOutputPath;

private File workingPath;
private File tempPath;

@Override
public void setSarlOutputPath(File path) {
Expand All @@ -60,8 +61,8 @@ public void setClassOutputPath(File path) {
}

@Override
public void setWorkingPath(File path) {
this.workingPath = path;
public void setTempDirectory(File path) {
this.tempPath = path;
}

@Override
Expand All @@ -75,28 +76,29 @@ public File getClassOutputPath() {
}

@Override
public File getWorkingPath() {
return this.workingPath;
public File getTempDirectory() {
return this.tempPath;
}

@Override
public void resolve(List<String> args) {
if (this.sarlOutputPath == null || this.workingPath == null || this.classOutputPath == null) {
@SuppressWarnings("checkstyle:npathcomplexity")
public void resolve(List<String> args) throws IOException {
if (this.sarlOutputPath == null || this.tempPath == null || this.classOutputPath == null) {
final Iterable<File> cliFiles = Iterables.transform(
args,
it -> toFile(it));
File root = determineCommonRoot(Iterables.concat(
cliFiles,
Collections.singleton(this.sarlOutputPath),
Collections.singleton(this.workingPath),
Collections.singleton(this.tempPath),
Collections.singleton(this.classOutputPath)));
if (root != null) {
root = normalize(root);
if (this.sarlOutputPath == null) {
this.sarlOutputPath = toFile(root, SARLConfig.FOLDER_SOURCE_GENERATED);
}
if (this.workingPath == null) {
this.workingPath = toFile(root, SARLConfig.FOLDER_TMP);
if (this.tempPath == null) {
this.tempPath = toFile(root, SARLConfig.FOLDER_TMP);
}
if (this.classOutputPath == null) {
this.classOutputPath = toFile(root, SARLConfig.FOLDER_BIN);
Expand Down
Expand Up @@ -22,6 +22,7 @@
package io.sarl.lang.sarlc.tools;

import java.io.File;
import java.io.IOException;
import java.util.List;

import com.google.inject.ImplementedBy;
Expand Down Expand Up @@ -55,11 +56,11 @@ public interface PathDetector {
*/
void setClassOutputPath(File path);

/** Change the working path.
/** Change the path in which the SARL compiler will write temp files.
*
* @param path the path.
*/
void setWorkingPath(File path);
void setTempDirectory(File path);

/** Replies the SARL output path.
*
Expand All @@ -73,16 +74,17 @@ public interface PathDetector {
*/
File getClassOutputPath();

/** Replies the working path.
/** Replies th path in which the SARL compiler will write temp files.
*
* @return the path.
*/
File getWorkingPath();
File getTempDirectory();

/** Resolve the paths.
*
* @param args the command line arguments to consider.
* @throws IOException if one path cannot be canonized.
*/
void resolve(List<String> args);
void resolve(List<String> args) throws IOException;

}
Expand Up @@ -46,6 +46,8 @@

/**
* Provider of the SARL SDK class path.
* The SARL libraries are supposed to be embedded into the sarlc archive file, into "embedded-sdk-libs" folder.
* The files into this folders are extracted into a temporary folder "sarlc-sdk-X.X".
*
* @author $Author: sgalland$
* @version $FullVersion$
Expand Down Expand Up @@ -156,6 +158,7 @@ private synchronized URL getSingleArchiveFromClasspath() {
while (iterator.hasNext()) {
final URL url = iterator.next();
if (singleUrl != null) {
// If more then 2 jar files are on the classpath, then there is not a single archive.
return null;
}
final File jarFile = FileSystem.convertURLToFile(url);
Expand Down

0 comments on commit 29a275a

Please sign in to comment.