diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 9aa9a79..9ecd7ae 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -47,7 +47,7 @@ jobs: dev.jbang.eclipse.site/target/flat-repository/* - name: Upload code coverage uses: codecov/codecov-action@v3 - if: github.ref == 'refs/heads/main' && runner.os == 'Linux' + if: runner.os == 'Linux' with: files: ./coverage/target/site/jacoco-aggregate/jacoco.xml flags: ${{ runner.os }} # optional diff --git a/dev.jbang.eclipse.core/plugin.xml b/dev.jbang.eclipse.core/plugin.xml index d332230..5cbea56 100644 --- a/dev.jbang.eclipse.core/plugin.xml +++ b/dev.jbang.eclipse.core/plugin.xml @@ -16,7 +16,7 @@ - diff --git a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/JBangConstants.java b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/JBangConstants.java index 91970b1..a9e09d8 100644 --- a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/JBangConstants.java +++ b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/JBangConstants.java @@ -11,23 +11,31 @@ public final class JBangConstants { public static final String BUILDER_ID = PLUGIN_ID + ".jbangbuilder"; //$NON-NLS-1$ public static final String MARKER_ID = PLUGIN_ID + ".jbangproblem"; //$NON-NLS-1$ - + public static final String MARKER_RESOLUTION_ID = MARKER_ID + ".resolution"; //$NON-NLS-1$ - - private static final String PREFIX = "dev.jbang."; - - /** String, list of configured JBang installations separated by '|', see {@link JBangRuntimeManager} */ - public static final String P_RUNTIMES = PREFIX + "runtimes"; //$NON-NLS-1$ - /** Root node of extended JBang installation attributes, see {@link JBangRuntimeManager} */ - public static final String P_RUNTIMES_NODE = PREFIX + "runtimesNodes"; //$NON-NLS-1$ + private static final String PREFIX = "dev.jbang."; - /** String */ - public static final String P_DEFAULT_RUNTIME = PREFIX + "defaultRuntime"; //$NON-NLS-1$ + /** + * String, list of configured JBang installations separated by '|', see + * {@link JBangRuntimeManager} + */ + public static final String P_RUNTIMES = PREFIX + "runtimes"; //$NON-NLS-1$ + /** + * Root node of extended JBang installation attributes, see + * {@link JBangRuntimeManager} + */ + public static final String P_RUNTIMES_NODE = PREFIX + "runtimesNodes"; //$NON-NLS-1$ + + public static final String P_DEFAULT_RUNTIME = PREFIX + "defaultRuntime"; //$NON-NLS-1$ + + public static final String JBANG_BUILD = "build.jbang"; - private JBangConstants(){ - //no instanciation - } + public static final String JBANG_MAIN = "main.java"; + + private JBangConstants() { + // no instanciation + } } diff --git a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/JBangFileUtils.java b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/JBangFileUtils.java index d9bdd72..bf7a3cb 100644 --- a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/JBangFileUtils.java +++ b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/JBangFileUtils.java @@ -1,10 +1,7 @@ package dev.jbang.eclipse.core.internal; -import java.io.BufferedInputStream; import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.file.Files; @@ -15,7 +12,6 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.CompilationUnit; @@ -67,6 +63,13 @@ public static boolean isJBangFile(IResource resource) { return false; } + public static boolean isJBangBuildFile(IResource resource) { + if (!(resource instanceof IFile)) { + return false; + } + return JBangConstants.JBANG_BUILD.equals(((IFile) resource).getName()); + } + public static boolean isJBangFile(Path file) { if (!(Files.isRegularFile(file))) { return false; @@ -84,6 +87,20 @@ public static boolean isJBangFile(Path file) { return false; } + public static boolean isJBangBuildFile(Path file) { + if (!(Files.isRegularFile(file))) { + return false; + } + return JBangConstants.JBANG_BUILD.equals(file.getFileName().toString()); + } + + public static boolean isMainFile(Path file) { + if (!(Files.isRegularFile(file))) { + return false; + } + return JBangConstants.JBANG_MAIN.equals(file.getFileName().toString()); + } + public static String getJavaVersion(String line) { return getMatch(JAVA_INSTRUCTION, line); } @@ -114,28 +131,33 @@ private static String getMatch(Pattern pattern, String line) { public static String getPackageName(IJavaProject javaProject, IFile file) { //TODO probably not the most efficient way to get the package name as this reads the whole file; - char[] source = null; - try (InputStream is = new BufferedInputStream(file.getContents(true)); - ByteArrayOutputStream result = new ByteArrayOutputStream()) { - byte[] buffer = new byte[1024]; - for (int length; (length = is.read(buffer)) != -1; ) { - result.write(buffer, 0, length); - } - source = result.toString(file.getCharset()).toCharArray(); - } catch (IOException | CoreException e) { + var ast = createCompilationUnit(file); + if (ast != null) { + PackageDeclaration pkg = ast.getPackage(); + if (pkg != null && pkg.getName() != null) { + return pkg.getName().getFullyQualifiedName(); + } + } + return null; + } + + public static CompilationUnit createCompilationUnit(IFile file) { + String content = null; + try { + content = ResourceUtil.getContent(file); + } catch (Exception e) { e.printStackTrace(); } - if (source == null) { + if (content == null) { return null; } + char[] source = content.toCharArray(); ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); - parser.setProject(javaProject); parser.setIgnoreMethodBodies(true); parser.setSource(source); CompilationUnit ast = (CompilationUnit) parser.createAST(null); - PackageDeclaration pkg = ast.getPackage(); - return (pkg == null || pkg.getName() == null)? null :pkg.getName().getFullyQualifiedName(); + return ast; } private static boolean hasJBangInstructions(Reader reader) throws IOException { diff --git a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/builder/JBangBuilder.java b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/builder/JBangBuilder.java index 7e1cf60..8d31f81 100644 --- a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/builder/JBangBuilder.java +++ b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/builder/JBangBuilder.java @@ -1,6 +1,8 @@ package dev.jbang.eclipse.core.internal.builder; import static dev.jbang.eclipse.core.JBangCorePlugin.logInfo; +import static dev.jbang.eclipse.core.internal.JBangFileUtils.createCompilationUnit; +import static dev.jbang.eclipse.core.internal.JBangFileUtils.isJBangBuildFile; import static dev.jbang.eclipse.core.internal.JBangFileUtils.isJBangFile; import java.util.ArrayList; @@ -26,6 +28,7 @@ import org.eclipse.jdt.core.manipulation.CoreASTProvider; import dev.jbang.eclipse.core.JBangCorePlugin; +import dev.jbang.eclipse.core.internal.ResourceUtil; import dev.jbang.eclipse.core.internal.project.JBangProject; import dev.jbang.eclipse.core.internal.project.ProjectConfigurationManager; import dev.jbang.eclipse.core.internal.runtime.JBangRuntimesDiscoveryJob; @@ -143,7 +146,7 @@ public boolean visit(IResourceDelta delta) { case IResourceDelta.CHANGED: { // if the content has changed clean + scan if ((delta.getFlags() & IResourceDelta.CONTENT) > 0) { - if (isJBangFile(resource)) { + if (isJBangBuildFile(resource) || isJBangFile(resource)) { jbangFiles.add((IFile) resource); } return true; @@ -166,21 +169,34 @@ void cleanMarkers(IProject p) { @SuppressWarnings("unchecked") static Integer getConfigHash(IFile file, IProgressMonitor monitor) throws CoreException { - if (!"java".equals(file.getFileExtension())) { + if (!JavaCore.isJavaLikeFileName(file.getName()) && !isJBangBuildFile(file) ) { return null; } - ICompilationUnit typeRoot = JavaCore.createCompilationUnitFrom(file); - //FIXME This is uber slow. Once a file is saved, its AST is disposed, we're not benefiting from reusing a cached AST, - // hence pay the price of recomputing it from scratch - CompilationUnit root = CoreASTProvider.getInstance().getAST(typeRoot, CoreASTProvider.WAIT_YES, monitor); + + CompilationUnit root = null; + String source = null; + if (isJBangBuildFile(file)) { + root = createCompilationUnit(file); + source = ResourceUtil.getContent(file); + } else { + ICompilationUnit typeRoot = JavaCore.createCompilationUnitFrom(file); + if (typeRoot != null) { + //FIXME This is uber slow. Once a file is saved, its AST is disposed, we're not benefiting from reusing a cached AST, + // hence pay the price of recomputing it from scratch + root = CoreASTProvider.getInstance().getAST(typeRoot, CoreASTProvider.WAIT_YES, monitor); + source = typeRoot.getSource(); + } + } if (root == null) { return 0; } - JBangConfigVisitor configCollector = new JBangConfigVisitor(typeRoot.getSource()); + + JBangConfigVisitor configCollector = new JBangConfigVisitor(source); root.accept(configCollector); for (Comment comment : (List) root.getCommentList()) { comment.accept(configCollector); } return configCollector.getConfigElements().hashCode(); - } + } + } diff --git a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/classpath/AnnotationProcessorUtils.java b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/classpath/AnnotationProcessorUtils.java index cd1a54f..2e6274e 100644 --- a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/classpath/AnnotationProcessorUtils.java +++ b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/classpath/AnnotationProcessorUtils.java @@ -12,7 +12,6 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -21,14 +20,10 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; import dev.jbang.eclipse.core.internal.classpath.AnnotationServiceLocator.ServiceEntry; diff --git a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/expressions/JBangResourceTester.java b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/expressions/JBangResourceTester.java index cccdaf6..03e41d6 100644 --- a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/expressions/JBangResourceTester.java +++ b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/expressions/JBangResourceTester.java @@ -17,7 +17,7 @@ public class JBangResourceTester extends PropertyTester { public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (receiver instanceof IResource) { IResource resource = (IResource) receiver; - boolean isJBangFile = JBangFileUtils.isJBangFile(resource); + boolean isJBangFile = JBangFileUtils.isJBangFile(resource) || JBangFileUtils.isJBangBuildFile(resource); return Objects.equals(isJBangFile, expectedValue); } return false; diff --git a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/imports/ImportJBangScriptsJob.java b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/imports/ImportJBangScriptsJob.java index 3e8698a..53a91d9 100644 --- a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/imports/ImportJBangScriptsJob.java +++ b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/imports/ImportJBangScriptsJob.java @@ -36,7 +36,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) { var configuration = new JBangProjectConfiguration(); for (Path script : scripts) { try { - if (JBangFileUtils.isJBangFile(script)) { + if (JBangFileUtils.isJBangFile(script) || JBangFileUtils.isJBangBuildFile(script)) { projectManager.createJBangProject(script, configuration, monitor); } } catch (Exception e) { diff --git a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/project/ProjectConfigurationManager.java b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/project/ProjectConfigurationManager.java index 5f278eb..68f920f 100644 --- a/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/project/ProjectConfigurationManager.java +++ b/dev.jbang.eclipse.core/src/main/java/dev/jbang/eclipse/core/internal/project/ProjectConfigurationManager.java @@ -38,7 +38,6 @@ import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.jdt.launching.environments.IExecutionEnvironment; import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; @@ -46,6 +45,7 @@ import dev.jbang.eclipse.core.JBangCorePlugin; import dev.jbang.eclipse.core.internal.JBangClasspathUtils; import dev.jbang.eclipse.core.internal.JBangConstants; +import dev.jbang.eclipse.core.internal.JBangFileUtils; import dev.jbang.eclipse.core.internal.ProjectUtils; import dev.jbang.eclipse.core.internal.ResourceUtil; import dev.jbang.eclipse.core.internal.classpath.AnnotationProcessorUtils; @@ -315,6 +315,9 @@ public JBangProject createJBangProject(java.nio.file.Path script, JBangProjectCo String fileName = script.getFileName().toString(); String name = fileName; //fileName.substring(0, fileName.lastIndexOf(".")); + if (JBangFileUtils.isJBangBuildFile(script) || JBangFileUtils.isMainFile(script)) { + name = script.getParent().getFileName().toString(); + } IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (!project.exists()) { @@ -353,7 +356,12 @@ public JBangProject createJBangProject(java.nio.file.Path script, JBangProjectCo javaProject.setOutputLocation(bin.getFullPath(), monitor); - IFile mainFile = link(info.getBackingResource(), project, configuration, monitor); + IFile mainFile; + if (JBangFileUtils.isJBangBuildFile(script)) { + mainFile = link(script.toAbsolutePath().toString(), project, configuration, monitor); + } else { + mainFile = link(info.getBackingResource(), project, configuration, monitor); + } if (info.getSources() != null && !info.getSources().isEmpty()) { for (JBangFile s : info.getSources()) { link(s.originalResource, project, configuration, monitor); @@ -424,10 +432,12 @@ public void synchronize(IFile file, IProgressMonitor monitor) throws CoreExcepti }); } } - } - private String getSource(IFile file) throws JavaModelException { + private String getSource(IFile file) throws CoreException { + if (JBangFileUtils.isJBangBuildFile(file)) { + return ResourceUtil.getContent(file); + } ICompilationUnit typeRoot = JavaCore.createCompilationUnitFrom(file); return typeRoot.getBuffer().getContents(); } diff --git a/dev.jbang.eclipse.ls/src/main/java/dev/jbang/eclipse/ls/internal/JBangFileDetector.java b/dev.jbang.eclipse.ls/src/main/java/dev/jbang/eclipse/ls/internal/JBangFileDetector.java index 890d148..ac176a4 100644 --- a/dev.jbang.eclipse.ls/src/main/java/dev/jbang/eclipse/ls/internal/JBangFileDetector.java +++ b/dev.jbang.eclipse.ls/src/main/java/dev/jbang/eclipse/ls/internal/JBangFileDetector.java @@ -44,6 +44,9 @@ public class JBangFileDetector { private static final String METADATA_FOLDER = "**/.metadata"; private static final Set FOLLOW_LINKS_OPTION = EnumSet.of(FileVisitOption.FOLLOW_LINKS); private List scripts; + private List mains; + private List builds; + private Path rootDir; private int maxDepth = 2; private Set exclusions = new LinkedHashSet<>(1); @@ -62,6 +65,8 @@ public class JBangFileDetector { public JBangFileDetector(Path rootDir) { this.rootDir = rootDir; scripts = new ArrayList<>(); + builds = new ArrayList<>(); + mains = new ArrayList<>(); addExclusions(METADATA_FOLDER); List javaImportExclusions = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getJavaImportExclusions(); if (javaImportExclusions != null) { @@ -96,12 +101,28 @@ public JBangFileDetector maxDepth(int maxDepth) { } /** - * Returns the scripts found to be containing the sought-after file. + * Returns the scripts found. * @return an unmodifiable collection of {@link Path}s. */ public Collection getScripts() { return Collections.unmodifiableList(scripts); } + + /** + * Returns the "main.java" scripts found. + * @return an unmodifiable collection of {@link Path}s. + */ + public Collection getMains() { + return Collections.unmodifiableList(mains); + } + + /** + * Returns the build.jbang files found. + * @return an unmodifiable collection of {@link Path}s. + */ + public Collection getBuildFiles() { + return Collections.unmodifiableList(builds); + } /** * Scan the the directories found to be containing the sought-after file. @@ -115,6 +136,13 @@ public Collection scan(IProgressMonitor monitor) throws CoreException { } catch (IOException e) { throw new CoreException(StatusFactory.newErrorStatus("Failed to scan "+rootDir, e)); } + if (!builds.isEmpty()) { + return getBuildFiles(); + } + if (!mains.isEmpty()) { + return getMains(); + } + return getScripts(); } @@ -134,7 +162,11 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if (JBangFileUtils.isJBangFile(file)) { + if (JBangFileUtils.isJBangBuildFile(file)) { + builds.add(file); + } else if (JBangFileUtils.isMainFile(file)) { + mains.add(file); + } else if (JBangFileUtils.isJBangFile(file)) { scripts.add(file); } return CONTINUE; diff --git a/dev.jbang.eclipse.ls/src/main/java/dev/jbang/eclipse/ls/internal/JBangImporter.java b/dev.jbang.eclipse.ls/src/main/java/dev/jbang/eclipse/ls/internal/JBangImporter.java index 410a5e8..308c7dd 100644 --- a/dev.jbang.eclipse.ls/src/main/java/dev/jbang/eclipse/ls/internal/JBangImporter.java +++ b/dev.jbang.eclipse.ls/src/main/java/dev/jbang/eclipse/ls/internal/JBangImporter.java @@ -16,6 +16,7 @@ import org.eclipse.jdt.ls.core.internal.ProjectUtils; import dev.jbang.eclipse.core.JBangCorePlugin; +import dev.jbang.eclipse.core.internal.JBangFileUtils; import dev.jbang.eclipse.core.internal.project.JBangProjectConfiguration; @SuppressWarnings("restriction") @@ -44,6 +45,9 @@ public void importToWorkspace(IProgressMonitor monitor) throws OperationCanceled for (Path script : scripts) { try { String name = script.getFileName().toString(); + if (JBangFileUtils.isJBangBuildFile(script) || JBangFileUtils.isMainFile(script)) { + name = script.getParent().getFileName().toString(); + } IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); //TODO Better check the script is actually bound to that project //TODO Trigger classpath update on the project @@ -73,5 +77,4 @@ public void reset() { scripts = null; } - } diff --git a/dev.jbang.eclipse.target/dev.jbang.eclipse.target b/dev.jbang.eclipse.target/dev.jbang.eclipse.target index 8682a76..f9fcf29 100644 --- a/dev.jbang.eclipse.target/dev.jbang.eclipse.target +++ b/dev.jbang.eclipse.target/dev.jbang.eclipse.target @@ -37,7 +37,7 @@ - + @@ -53,4 +53,4 @@ - + \ No newline at end of file diff --git a/dev.jbang.eclipse.test/scripts/foo/build.jbang b/dev.jbang.eclipse.test/scripts/foo/build.jbang new file mode 100644 index 0000000..1ee15ae --- /dev/null +++ b/dev.jbang.eclipse.test/scripts/foo/build.jbang @@ -0,0 +1,7 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//DEPS info.picocli:picocli:LATEST +//DESCRIPTION For testing purposes +//GAV dev.jbang.itests:foo +//SOURCES foo.java +//JAVA 11+ +//JAVA_OPTIONS -Dfoo=bar "-Dbar=aap noot mies" \ No newline at end of file diff --git a/dev.jbang.eclipse.test/scripts/foo/foo.java b/dev.jbang.eclipse.test/scripts/foo/foo.java new file mode 100644 index 0000000..295b3f1 --- /dev/null +++ b/dev.jbang.eclipse.test/scripts/foo/foo.java @@ -0,0 +1,24 @@ +import java.util.Map; + +import picocli.CommandLine; +import picocli.CommandLine.Option; + +public class foo implements Runnable { + @Option(names = "-fix", split = "\\|") + Map message; + + @Option(names = "-other") + String other; + + @Override + public void run() { + if(System.getProperty("value")!=null) { + System.out.print("value::" + System.getProperty("value") + " "); + } + System.out.println("other: [" + (other==null?"":other) + "] " + "fix : " + message); + } + + public static void main(String[] args) { + new CommandLine(new foo()).execute(args); + } +} \ No newline at end of file diff --git a/dev.jbang.eclipse.test/src/main/java/dev/jbang/eclipse/core/internal/ImportScriptTest.java b/dev.jbang.eclipse.test/src/main/java/dev/jbang/eclipse/core/internal/ImportScriptTest.java index 24879a2..d54d648 100644 --- a/dev.jbang.eclipse.test/src/main/java/dev/jbang/eclipse/core/internal/ImportScriptTest.java +++ b/dev.jbang.eclipse.test/src/main/java/dev/jbang/eclipse/core/internal/ImportScriptTest.java @@ -58,4 +58,18 @@ public void importScriptWithDependency() throws Exception { var dependency = script.getParent().getFile(new Path("dependency.java")); assertTrue(dependency.exists(), dependency.getName() + " doesn't exist"); } + + @Test + public void importJBangBuild() throws Exception { + var jbp = importJBangScript("foo/build.jbang", "foo/foo.java"); + assertNotNull(jbp); + assertEquals("foo", jbp.getProject().getName()); + waitForJobsToComplete(); + IProject project = jbp.getProject(); + assertNoErrors(project); + var build = jbp.getMainSourceFile(); + assertEquals("build.jbang", build.getName()); + var foo = build.getParent().getFile(new Path("foo.java")); + assertTrue(foo.exists(), foo.getName() + " doesn't exist"); + } } diff --git a/dev.jbang.eclipse.test/src/main/java/dev/jbang/eclipse/core/internal/utils/ImportScriptUtils.java b/dev.jbang.eclipse.test/src/main/java/dev/jbang/eclipse/core/internal/utils/ImportScriptUtils.java index 5ad66d0..e52d96e 100644 --- a/dev.jbang.eclipse.test/src/main/java/dev/jbang/eclipse/core/internal/utils/ImportScriptUtils.java +++ b/dev.jbang.eclipse.test/src/main/java/dev/jbang/eclipse/core/internal/utils/ImportScriptUtils.java @@ -26,7 +26,7 @@ public static JBangProject importJBangScript(String... relativePaths) throws Exc for (String relativePath : relativePaths) { var scriptPath = scriptsDir.resolve(relativePath); if (!Files.exists(scriptPath)) { - throw new IOException(scriptPath + " does not exist"); + throw new IOException("Import failed: "+scriptPath + " does not exist"); } var destPath = copy(workDir, scriptPath); @@ -47,7 +47,7 @@ private static Path copy(Path destFolder, Path scriptPath) throws IOException { var destPath = destFolder.resolve(scriptsDir.relativize(scriptPath)); Files.deleteIfExists(destPath); - + Files.createDirectories(destPath.getParent()); Files.copy(scriptPath, destPath); return destPath; } diff --git a/dev.jbang.eclipse.ui/src/main/java/dev/jbang/eclipse/ui/internal/commands/SynchronizeJBangHandler.java b/dev.jbang.eclipse.ui/src/main/java/dev/jbang/eclipse/ui/internal/commands/SynchronizeJBangHandler.java index f405f28..5016f46 100644 --- a/dev.jbang.eclipse.ui/src/main/java/dev/jbang/eclipse/ui/internal/commands/SynchronizeJBangHandler.java +++ b/dev.jbang.eclipse.ui/src/main/java/dev/jbang/eclipse/ui/internal/commands/SynchronizeJBangHandler.java @@ -1,5 +1,6 @@ package dev.jbang.eclipse.ui.internal.commands; +import static dev.jbang.eclipse.core.internal.JBangFileUtils.isJBangBuildFile; import static dev.jbang.eclipse.core.internal.JBangFileUtils.isJBangFile; import java.util.LinkedHashSet; @@ -63,7 +64,7 @@ private Set collectFiles(Object[] elements) { Set files = new LinkedHashSet<>(); for (Object element : elements) { IResource file = Adapters.adapt(element, IResource.class); - if (file != null && isJBangFile(file) && file.getLocation() != null) { + if (file != null && (isJBangFile(file) || isJBangBuildFile(file)) && file.getLocation() != null) { files.add((IFile) file); } } diff --git a/dev.jbang.eclipse.ui/src/main/java/dev/jbang/eclipse/ui/internal/wizards/JBangImportWizardPage.java b/dev.jbang.eclipse.ui/src/main/java/dev/jbang/eclipse/ui/internal/wizards/JBangImportWizardPage.java index 1667cc7..c3a6800 100644 --- a/dev.jbang.eclipse.ui/src/main/java/dev/jbang/eclipse/ui/internal/wizards/JBangImportWizardPage.java +++ b/dev.jbang.eclipse.ui/src/main/java/dev/jbang/eclipse/ui/internal/wizards/JBangImportWizardPage.java @@ -66,7 +66,7 @@ public void createControl(Composite parent) { browseButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); browseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { FileDialog dialog = new FileDialog(getShell(), SWT.NONE); - dialog.setFilterExtensions(new String[] { "*.java","*.jsh","*.kt","*.groovy" }); + dialog.setFilterExtensions(new String[] { "*.java","*.jsh","*.kt","*.groovy", "build.jbang" }); dialog.setText("Select script"); String result = dialog.open(); if (result != null) {