Skip to content

Commit

Permalink
Merge branch 'master' into issue/5988-dependencybot-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
pkriens authored Jan 24, 2024
2 parents a14ac2f + 4295b85 commit 079a364
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Git Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Ruby
uses: ruby/setup-ruby@432702e864cadc1b56247e31aa341be5be3e129a
uses: ruby/setup-ruby@5daca165445f0ae10478593083f72ca2625e241d
with:
ruby-version: 2.7
bundler-cache: true
Expand Down
2 changes: 1 addition & 1 deletion bndtools.core/src/org/bndtools/facade/package-info.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@org.osgi.annotation.bundle.Export
@org.osgi.annotation.versioning.Version("1.0.0")
@org.osgi.annotation.versioning.Version("1.1.0")
package org.bndtools.facade;
36 changes: 18 additions & 18 deletions bndtools.core/src/org/bndtools/refactor/types/GogoRefactorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,6 @@ public void addGogo() {
});
}

private String scrunch(String string) {
String s = string.toLowerCase();
if (s.length() < 8)
return s;

StringBuilder result = new StringBuilder(s);
for (int i = result.length() - 1; i >= 0 && result.length() > 8; i--) {
char c = result.charAt(i);
if (!Character.isAlphabetic(c) || "aeiou".indexOf(c) >= 0) {
result.delete(i, 1);
}
}
if (result.length() > 8) {
result.delete(8, result.length());
}
return result.toString();
}

String[] calculateNames(String name) {
if (name.length() < 1)
return new String[0];
Expand Down Expand Up @@ -373,4 +355,22 @@ void doCommand(ProposalBuilder builder, Cursor<MethodDeclaration> methodDeclarat
() -> state.add(new Command(methodDeclaration)));
}

static public String scrunch(String string) {
String s = string.toLowerCase();
if (s.length() < 8)
return s;

StringBuilder result = new StringBuilder(s);
for (int i = result.length() - 1; i >= 0 && result.length() > 8; i--) {
char c = result.charAt(i);
if (!Character.isAlphabetic(c) || "aeiou".indexOf(c) >= 0) {
result.delete(i, i + 1);
}
}
if (result.length() > 8) {
result.delete(8, result.length());
}
return result.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bndtools.refactor.util.RefactorAssistant;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand Down Expand Up @@ -164,4 +165,11 @@ static List<Scenario> scenarios() {
//@formatter:on
);
}

@Test
public void testScrunch() {
assertThat(GogoRefactorer.scrunch("TestRefactors")).isEqualTo("tstrfctr");
assertThat(GogoRefactorer.scrunch("foobarffoo")).isEqualTo("foobarff");

}
}
31 changes: 31 additions & 0 deletions bndtools.core/test/org/bndtools/refactor/types/TestRefactors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.bndtools.refactor.types;

import java.util.Date;

import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

@Component
public class TestRefactors {

interface Bar {}

@Activate
public TestRefactors(BundleContext context, @Reference
Bar serice) {}

@Reference
void setBar(Bar bar) {}

void unsetBar(Bar bar) {}

Date getDate() {
return new Date();
}

@Deactivate
void close() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Version("1.0.0")
@Export
package org.bndtools.refactor.types;

import org.osgi.annotation.versioning.Version;
import org.osgi.annotation.bundle.Export;
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.core.filesystem.provider.FileInfo;
import org.eclipse.core.filesystem.provider.FileStore;
import org.eclipse.core.filesystem.provider.FileSystem;
import org.eclipse.core.internal.filesystem.NullFileStore;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -50,11 +49,10 @@
* jarfileuri ::= <any uri including jarf>
* </pre>
*
* @author aqute
*/
public class JarFileSystem extends FileSystem {
private static final ILogger logger = Logger.getLogger(JarFileSystem.class);

@SuppressWarnings("unused")
private static final String SCHEME_JARF = "jarf";
private final ConcurrentMap<IFileStore, Reference<JarRootNode>> roots = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -98,9 +96,10 @@ public String[] childNames(int options, IProgressMonitor monitor) throws CoreExc

@Override
public IFileStore getChild(String name) {
return new NullFileStore(new Path(getPath()).append(name));
return nullFileStore(new Path(getPath()).append(name));
}


@Override
public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException {
return new ByteArrayInputStream(new byte[0]);
Expand Down Expand Up @@ -212,7 +211,7 @@ public InputStream openInputStream(int options, IProgressMonitor monitor) throws
public IFileStore getStore(URI uri) {
if (!SCHEME_JARF.equals(uri.getScheme())) {
logger.logError("No file system for : " + uri, null);
return new NullFileStore(Path.EMPTY);
return nullFileStore(new Path(uri.getPath()));
}
return jarf(uri).map(pair -> {
URI fileuri = pair.getFirst();
Expand All @@ -221,14 +220,14 @@ public IFileStore getStore(URI uri) {
store = EFS.getStore(fileuri);
} catch (CoreException e) {
logger.logError("Cannot locate filestore for the JAR file: " + fileuri, e);
return new NullFileStore(Path.EMPTY);
return nullFileStore(Path.EMPTY);
}

JarRootNode root = roots.compute(store, this::computeRootNode)
.get();
if (root == null) {
logger.logError("Failed to load jar for: " + fileuri, null);
return new NullFileStore(Path.EMPTY);
return nullFileStore(Path.EMPTY);
}

IPath path = pair.getSecond();
Expand All @@ -240,7 +239,7 @@ public IFileStore getStore(URI uri) {
})
.recover(err -> {
logger.logError(err, null);
return new NullFileStore(Path.EMPTY);
return nullFileStore(Path.EMPTY);
})
.unwrap();
}
Expand Down Expand Up @@ -330,4 +329,9 @@ static Result<InputStream> openInputStream(URI uri, String path, IProgressMonito
return Result.err("Failed to open resource %s from %s : %s", path, uri, e);
}
}

static IFileStore nullFileStore(IPath path) {
return EFS.getNullFileSystem()
.getStore(path);
}
}

0 comments on commit 079a364

Please sign in to comment.