Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Ports/JavaSE/src/com/codename1/impl/javase/CSSWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ File findLocalizationDirectory(File srcFile, String overrideInputs) {
}

/**
* Adds likely l10n locations derived from the CSS file and current working directory.
* Adds likely l10n/i18n locations derived from the CSS file and current working directory.
* <p>We include relative common-module paths because JavaSE watch is often launched
* from the `javase` module while CSS/l10n are in `../common/src/main`.</p>
* from the `javase` module while CSS/localization resources are in `../common/src/main`.</p>
*/
void addLocalizationCandidates(File cssFile, List<File> out) {
if (cssFile == null) {
Expand All @@ -164,13 +164,17 @@ void addLocalizationCandidates(File cssFile, List<File> out) {
File srcMainDirectory = cssDirectory.getParentFile();
if (srcMainDirectory != null) {
out.add(new File(srcMainDirectory, "l10n"));
out.add(new File(srcMainDirectory, "i18n"));
}
}

File workingDirectory = new File(System.getProperty("user.dir"));
out.add(new File(workingDirectory, "l10n"));
out.add(new File(workingDirectory, "i18n"));
out.add(new File(workingDirectory, "src/main/l10n"));
out.add(new File(workingDirectory, "src/main/i18n"));
out.add(new File(workingDirectory, "../common/src/main/l10n"));
out.add(new File(workingDirectory, "../common/src/main/i18n"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,43 @@ protected File findLocalizationDirectory() {
if (parent == null) {
continue;
}
File localizationSibling = new File(parent, "l10n");
if (hasLocalizationDirectory(localizationSibling)) {
File localizationSibling = findLocalizationSibling(parent);
if (localizationSibling != null) {
return localizationSibling;
}
}
}

File cn1ProjectDir = getCN1ProjectDir();
if (cn1ProjectDir != null) {
File defaultLocalization = new File(cn1ProjectDir, path("src", "main", "l10n"));
if (hasLocalizationDirectory(defaultLocalization)) {
return defaultLocalization;
File sourceLocalization = findLocalizationSibling(new File(cn1ProjectDir, path("src", "main")));
if (sourceLocalization != null) {
return sourceLocalization;
}
File rootLocalization = new File(cn1ProjectDir, "l10n");
if (hasLocalizationDirectory(rootLocalization)) {
File rootLocalization = findLocalizationSibling(cn1ProjectDir);
if (rootLocalization != null) {
return rootLocalization;
}
}

return null;
}

private File findLocalizationSibling(File parent) {
if (parent == null) {
return null;
}
File l10n = new File(parent, "l10n");
if (hasLocalizationDirectory(l10n)) {
return l10n;
}
File i18n = new File(parent, "i18n");
if (hasLocalizationDirectory(i18n)) {
return i18n;
}
return null;
}

/**
* Treats an existing l10n directory as a valid localization source.
* <p>This intentionally does not require `.properties` files up-front because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CompileCSSMojoTest {

@Test
void addsLocalizationDirectoryToDesignerInvocation(@TempDir Path tempDir) throws Exception {
Path projectDir = setupProject(tempDir, true);
Path projectDir = setupProject(tempDir, "l10n");
TestCompileCSSMojo mojo = createMojo(projectDir);

mojo.executeImpl();
Expand All @@ -40,7 +40,7 @@ void addsLocalizationDirectoryToDesignerInvocation(@TempDir Path tempDir) throws

@Test
void skipsLocalizationArgumentWhenDirectoryMissing(@TempDir Path tempDir) throws Exception {
Path projectDir = setupProject(tempDir, false);
Path projectDir = setupProject(tempDir, null);
TestCompileCSSMojo mojo = createMojo(projectDir);

mojo.executeImpl();
Expand All @@ -51,7 +51,7 @@ void skipsLocalizationArgumentWhenDirectoryMissing(@TempDir Path tempDir) throws

@Test
void addsLocalizationArgumentWhenDirectoryIsEmpty(@TempDir Path tempDir) throws Exception {
Path projectDir = setupProject(tempDir, false);
Path projectDir = setupProject(tempDir, null);
Files.createDirectories(projectDir.resolve("src/main/l10n"));
TestCompileCSSMojo mojo = createMojo(projectDir);

Expand All @@ -64,6 +64,20 @@ void addsLocalizationArgumentWhenDirectoryIsEmpty(@TempDir Path tempDir) throws
assertEquals(projectDir.resolve("src/main/l10n").toFile().getAbsolutePath(), args.get(index + 1));
}

@Test
void addsI18nDirectoryToDesignerInvocation(@TempDir Path tempDir) throws Exception {
Path projectDir = setupProject(tempDir, "i18n");
TestCompileCSSMojo mojo = createMojo(projectDir);

mojo.executeImpl();

List<String> args = mojo.getRecordingJava().getCommandLineArguments();
assertTrue(args.contains("-l"), "Expected -l argument when i18n directory exists");
int index = args.indexOf("-l");
assertTrue(index >= 0 && index + 1 < args.size(), "Expected localization directory argument after -l");
assertEquals(projectDir.resolve("src/main/i18n").toFile().getAbsolutePath(), args.get(index + 1));
}

private TestCompileCSSMojo createMojo(Path projectDir) throws IOException {
MavenProject mavenProject = new MavenProject();
mavenProject.setFile(projectDir.resolve("pom.xml").toFile());
Expand All @@ -87,7 +101,7 @@ private TestCompileCSSMojo createMojo(Path projectDir) throws IOException {
return mojo;
}

private Path setupProject(Path tempDir, boolean includeLocalization) throws IOException {
private Path setupProject(Path tempDir, String localizationDirName) throws IOException {
Path projectDir = tempDir.resolve("project");
Files.createDirectories(projectDir);
Files.createDirectories(projectDir.resolve("src/main/java"));
Expand All @@ -107,8 +121,8 @@ private Path setupProject(Path tempDir, boolean includeLocalization) throws IOEx
"</project>"
));

if (includeLocalization) {
Path localizationDir = Files.createDirectories(projectDir.resolve("src/main/l10n"));
if (localizationDirName != null) {
Path localizationDir = Files.createDirectories(projectDir.resolve("src/main").resolve(localizationDirName));
Files.write(localizationDir.resolve("Messages.properties"), Arrays.asList("greeting=Hello"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public boolean isDarkMode() {
public boolean isSupported() {
return false;
}

public void notifyUiReady() {}
}
Loading