use of dev.jbang.source.SourceSet in project jbang by jbangdev.
the class TestEditWithPackage method testEditPackage.
@Test
void testEditPackage() throws IOException {
Path mainPath = TestSource.createTmpFileWithContent("", "A.java", classA);
Path BPath = TestSource.createTmpFileWithContent(mainPath.getParent(), "person", "B.java", classB);
Path CPath = TestSource.createTmpFileWithContent(BPath.getParent(), "model", "C.java", classC);
assertTrue(mainPath.toFile().exists());
RunContext ctx = RunContext.empty();
SourceSet ss = (SourceSet) ctx.forResource(mainPath.toString());
File project = new Edit().createProjectForEdit(ss, ctx, false);
assertTrue(new File(project, "src/A.java").exists());
assertTrue(new File(project, "src/person/B.java").exists());
assertTrue(new File(project, "src/person/model/C.java").exists());
File javaC = new File(project, "src/person/model/C.java");
// first check for symlink. in some cases on windows (non admin privileg)
// symlink cannot be created, as fallback a hardlink will be created.
assertTrue(Files.isSymbolicLink(javaC.toPath()) || javaC.exists());
assertTrue(Files.isSameFile(javaC.toPath(), CPath));
Arrays.asList("A.java", "person/B.java", "person/model/C.java").forEach(f -> {
File java = new File(project, "src/" + f);
assertThat(f + " not found", java, aReadableFile());
});
}
use of dev.jbang.source.SourceSet in project jbang by jbangdev.
the class TestEdit method testEditNonJava.
@Test
void testEditNonJava(@TempDir Path outputDir) throws IOException {
Path p = outputDir.resolve("kube-example");
int result = JBang.getCommandLine().execute("init", p.toString());
String s = p.toString();
assertThat(result, is(0));
assertThat(new File(s).exists(), is(true));
RunContext ctx = RunContext.empty();
SourceSet ss = (SourceSet) ctx.forResource(s);
File project = new Edit().createProjectForEdit(ss, ctx, false);
File java = new File(project, "src/KubeExample.java");
// symlink cannot be created, as fallback a hardlink will be created.
assert (Files.isSymbolicLink(java.toPath()) || java.exists());
}
use of dev.jbang.source.SourceSet in project jbang by jbangdev.
the class TestEdit method testEdit.
@Test
void testEdit(@TempDir Path outputDir) throws IOException {
String s = outputDir.resolve("edit.java").toString();
JBang.getCommandLine().execute("init", s);
assertThat(new File(s).exists(), is(true));
RunContext ctx = RunContext.empty();
SourceSet ss = (SourceSet) ctx.forResource(s);
File project = new Edit().createProjectForEdit(ss, ctx, false);
assertThat(new File(project, "src"), FileMatchers.anExistingDirectory());
File build = new File(project, "build.gradle");
assert (build.exists());
MatcherAssert.assertThat(Util.readString(build.toPath()), containsString("dependencies"));
File src = new File(project, "src/edit.java");
// symlink cannot be created, as fallback a hardlink will be created.
assert (Files.isSymbolicLink(src.toPath()) || src.exists());
// check eclipse is there
assertThat(Arrays.stream(project.listFiles()).map(File::getName).collect(Collectors.toList()), containsInAnyOrder(".project", ".classpath", ".eclipse", "src", "build.gradle", ".vscode", "README.md"));
File launchfile = new File(project, ".eclipse/edit.launch");
assert (launchfile.exists());
assertThat(Util.readString(launchfile.toPath()), containsString("launching.PROJECT_ATTR"));
assertThat(Util.readString(launchfile.toPath()), containsString("PROGRAM_ARGUMENTS\" value=\"\""));
launchfile = new File(project, ".eclipse/edit-port-4004.launch");
assert (launchfile.exists());
assertThat(Util.readString(launchfile.toPath()), containsString("launching.PROJECT_ATTR"));
assertThat(Util.readString(launchfile.toPath()), containsString("4004"));
}
use of dev.jbang.source.SourceSet in project jbang by jbangdev.
the class TestEdit method testEditMultiSource.
@Test
void testEditMultiSource(@TempDir Path outputDir) throws IOException {
Path p = examplesTestFolder.resolve("one.java");
assertThat(p.toFile().exists(), is(true));
RunContext ctx = RunContext.empty();
SourceSet ss = (SourceSet) ctx.forResource(p.toString());
File project = new Edit().createProjectForEdit(ss, ctx, false);
File gradle = new File(project, "build.gradle");
assert (gradle.exists());
assertThat(Util.readString(gradle.toPath()), not(containsString("bogus")));
Arrays.asList("one.java", "Two.java", "gh_fetch_release_assets.java", "gh_release_stats.java").forEach(f -> {
File java = new File(project, "src/" + f);
assertThat(f + " not found", java, aReadableFile());
});
}
use of dev.jbang.source.SourceSet in project jbang by jbangdev.
the class TestEdit method testEditFile.
@Test
void testEditFile(@TempDir Path outputDir) throws IOException {
Path p = examplesTestFolder.resolve("res/resource.java");
assertThat(p.toFile().exists(), is(true));
RunContext ctx = RunContext.empty();
SourceSet ss = (SourceSet) ctx.forResource(p.toString());
ss.getClassPath();
File project = new Edit().createProjectForEdit(ss, ctx, false);
File gradle = new File(project, "build.gradle");
assert (gradle.exists());
assertThat(Util.readString(gradle.toPath()), not(containsString("bogus")));
Arrays.asList("resource.java", "resource.properties", "renamed.properties", "META-INF/application.properties").forEach(f -> {
File java = new File(project, "src/" + f);
assertThat(f + " not found", java, aReadableFile());
});
}
Aggregations