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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ Several [bundle applications](#bundle-apps) using this framework are also availa

## Requirements

- **Running**: Java 11 or later
- **Running**: Java 17 or later
- **Building**: Java 17 or later (required by Gradle 9)

> **Note**: This is the last release supporting Java 11 as a runtime target.
> Future versions will require Java 17 or later.
> To run on Java 11, use the pre-built JAR from [v0.7.0](https://github.com/sh5i/git-stein/releases/tag/v0.7.0).


## Build and Run
Expand Down
23 changes: 4 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,14 @@ java {
// v61 (Java 17, LTS)
// v65 (Java 21, LTS)
// v69 (Java 25, LTS)
languageVersion = JavaLanguageVersion.of(11)
languageVersion = JavaLanguageVersion.of(17)
}
}

dependencies {
// jgit 7.x requires Java 17; staying on 6.x for Java 11 compatibility
api 'org.eclipse.jgit:org.eclipse.jgit:6.10.1.202505221210-r'

// JDT 3.29+ and eclipse platform require Java 17; staying on 3.28.x for Java 11 compatibility
implementation 'org.eclipse.jdt:org.eclipse.jdt.core:3.28.0'
implementation 'org.eclipse.platform:org.eclipse.core.commands:3.8.0'
implementation 'org.eclipse.platform:org.eclipse.core.contenttype:3.5.100'
implementation 'org.eclipse.platform:org.eclipse.core.expressions:3.5.100'
implementation 'org.eclipse.platform:org.eclipse.core.filesystem:1.7.0'
implementation 'org.eclipse.platform:org.eclipse.core.jobs:3.8.0'
implementation 'org.eclipse.platform:org.eclipse.core.resources:3.14.0'
implementation 'org.eclipse.platform:org.eclipse.core.runtime:3.13.0'
implementation 'org.eclipse.platform:org.eclipse.equinox.app:1.3.400'
implementation 'org.eclipse.platform:org.eclipse.equinox.common:3.8.0'
implementation 'org.eclipse.platform:org.eclipse.equinox.preferences:3.6.1'
implementation 'org.eclipse.platform:org.eclipse.equinox.registry:3.6.100'
implementation 'org.eclipse.platform:org.eclipse.osgi:3.11.2'
implementation 'org.eclipse.platform:org.eclipse.text:3.6.0'
api 'org.eclipse.jgit:org.eclipse.jgit:7.6.0.202603022253-r'

implementation 'org.eclipse.jdt:org.eclipse.jdt.core:3.45.0'

implementation 'org.slf4j:slf4j-api:2.0.17'
implementation 'ch.qos.logback:logback-classic:1.5.32'
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 1 addition & 4 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/main/java/jp/ac/titech/c/se/stein/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ public int execute(final ParseResult parseResult) throws ExecutionException, Par
// help
if (parseResult.subcommands().size() >= 2) {
final Object cmd = parseResult.subcommands().get(0).commandSpec().userObject();
if (cmd instanceof SettableHelpCommand) {
((SettableHelpCommand) cmd).setCommand(parseResult.subcommands().get(1).commandSpec().name());
if (cmd instanceof SettableHelpCommand shc) {
shc.setCommand(parseResult.subcommands().get(1).commandSpec().name());
}
}
if (CommandLine.printHelpIfRequested(parseResult)) {
Expand Down Expand Up @@ -310,8 +310,8 @@ public List<RewriterCommand> optimizeRewriters(final List<RewriterCommand> comma
final List<BlobTranslator> pending = new ArrayList<>();

for (final RewriterCommand cmd : commands) {
if (cmd instanceof BlobTranslator) {
pending.add((BlobTranslator) cmd);
if (cmd instanceof BlobTranslator t) {
pending.add(t);
} else {
flushPendingTranslators(pending, result);
result.add(cmd);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/jp/ac/titech/c/se/stein/app/Anonymize.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public AnyHotEntry rewriteBlobEntry(BlobEntry entry, final Context c) {
@Override
protected AnyColdEntry rewriteTreeEntry(TreeEntry entry, Context c) {
final AnyColdEntry result = super.rewriteTreeEntry(entry, c);
if (isTreeNameEnabled && result instanceof Entry) {
final Entry e = (Entry) result;
if (isTreeNameEnabled && result instanceof Entry e) {
return Entry.of(e.mode, treeNameMap.convert(e.name), e.id, e.directory);
}
return result;
Expand Down
19 changes: 5 additions & 14 deletions src/main/java/jp/ac/titech/c/se/stein/app/blob/Cregit.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,11 @@ protected void setLanguage(final String language) {
this.language = language;
if (filter.isDefault()) {
switch (language) {
case "C":
filter.setPatterns(C_EXT);
break;
case "C++":
filter.setPatterns(CXX_EXT);
break;
case "C#":
filter.setPatterns(CSHARP_EXT);
break;
case "Java":
filter.setPatterns(JAVA_EXT);
break;
default:
log.error("Unknown language: {}", language);
case "C" -> filter.setPatterns(C_EXT);
case "C++" -> filter.setPatterns(CXX_EXT);
case "C#" -> filter.setPatterns(CSHARP_EXT);
case "Java" -> filter.setPatterns(JAVA_EXT);
default -> log.error("Unknown language: {}", language);
}
}
}
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/jp/ac/titech/c/se/stein/app/blob/FilterBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,13 @@ public Long convert(final String value) {
final int len = value.length();
final char unit = Character.toUpperCase(value.charAt(len - 1));
final String num = value.substring(0, len - 1);
switch (unit) {
case 'B':
return convert(num);
case 'K':
return displaySizeToByteCount(num, 1024);
case 'M':
return displaySizeToByteCount(num, 1024 * 1024);
case 'G':
return displaySizeToByteCount(num, 1024 * 1024 * 1024);
default:
return displaySizeToByteCount(value, 1);
}
return switch (unit) {
case 'B' -> convert(num);
case 'K' -> displaySizeToByteCount(num, 1024);
case 'M' -> displaySizeToByteCount(num, 1024 * 1024);
case 'G' -> displaySizeToByteCount(num, 1024 * 1024 * 1024);
default -> displaySizeToByteCount(value, 1);
};
}

protected long displaySizeToByteCount(final String value, final long base) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public ClassModule(final String name, final Module parent, final String content,

@Override
public String getBasename() {
if (parent instanceof ClassModule) {
return parent.getBasename() + "." + name;
if (parent instanceof ClassModule cm) {
return cm.getBasename() + "." + name;
} else {
return parent.getBasename().equals(name) ? name : name + "[" + parent.getBasename() + "]";
}
Expand Down Expand Up @@ -300,8 +300,7 @@ protected CompilationUnit parse() {
* Creates a JDT ASTParser.
*/
protected ASTParser createParser() {
final ASTParser parser = ASTParser.newParser(AST.JLS17);
@SuppressWarnings("unchecked")
final ASTParser parser = ASTParser.newParser(AST.JLS25);
final Map<String, String> options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_17);
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_17);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public AnyHotEntry rewriteBlobEntry(final BlobEntry entry, final Context c) {
* Encodes the given source to linetoken format.
*/
public static String encode(final String source) {
final IScanner scanner = ToolFactory.createScanner(true, true, false, JavaCore.VERSION_17);
final IScanner scanner = ToolFactory.createScanner(true, true, false, JavaCore.VERSION_25);
scanner.setSource(source.toCharArray());
final StringBuilder buffer = new StringBuilder();
try {
Expand Down
22 changes: 8 additions & 14 deletions src/main/java/jp/ac/titech/c/se/stein/core/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,14 @@ protected String entryToString(final Map.Entry<Key, Object> e) {
}

protected static String getStringValue(final Key key, final Object value) {
switch (key) {
case commit:
return ((RevCommit) value).name();
case path:
return '"' + (String) value + '"';
case entry:
return value.toString();
case tag:
return ((RevTag) value).name();
case ref:
return ((Ref) value).getName();
default:
return null;
}
return switch (key) {
case commit -> ((RevCommit) value).name();
case path -> '"' + (String) value + '"';
case entry -> value.toString();
case tag -> ((RevTag) value).name();
case ref -> ((Ref) value).getName();
default -> null;
};
}

@Override
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/jp/ac/titech/c/se/stein/core/RepositoryAccess.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jp.ac.titech.c.se.stein.core;

import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -298,17 +297,11 @@ public ObjectId writeBlob(final byte[] data, final Context writingContext) {
public ObjectId copyTree(final ObjectId treeId, final RepositoryAccess target, final Context c) {
final List<Entry> entries = new ArrayList<>();
for (final Entry e : readTree(treeId, null)) {
switch (e.getType()) {
case TREE:
entries.add(Entry.of(e.getMode(), e.getName(), copyTree(e.getId(), target, c)));
break;
case BLOB:
entries.add(Entry.of(e.getMode(), e.getName(), copyBlob(e.getId(), target, c)));
break;
default:
entries.add(e);
break;
}
entries.add(switch (e.getType()) {
case tree -> Entry.of(e.getMode(), e.getName(), copyTree(e.getId(), target, c));
case blob -> Entry.of(e.getMode(), e.getName(), copyBlob(e.getId(), target, c));
default -> e;
});
}
return target.writeTree(entries, c);
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/jp/ac/titech/c/se/stein/entry/AnyColdEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,11 @@ public String toString() {

@Override
public AnyColdEntry normalize() {
switch (size()) {
case 0:
return empty();
case 1:
return entries.get(0);
default:
return this;
}
return switch (size()) {
case 0 -> empty();
case 1 -> entries.get(0);
default -> this;
};
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/jp/ac/titech/c/se/stein/entry/BlobEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @see SourceBlob
* @see NewBlob
*/
public abstract class BlobEntry extends HotEntry {
public abstract sealed class BlobEntry extends HotEntry permits BlobEntry.SourceBlob, BlobEntry.NewBlob {
public abstract byte[] getBlob();

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ public NewBlob update(final String newContent) {
* The blob content is lazily loaded on the first call to {@link #getBlob()}.
*/
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public static class SourceBlob extends BlobEntry {
public static final class SourceBlob extends BlobEntry {
@Delegate(types = SingleEntry.class)
private final Entry entry;

Expand Down Expand Up @@ -93,7 +93,7 @@ public String toString() {
*/
@Slf4j
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public static class NewBlob extends BlobEntry {
public static final class NewBlob extends BlobEntry {
@Getter
private final int mode;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jp/ac/titech/c/se/stein/entry/HotEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @see TreeEntry
* @see Entry
*/
public abstract class HotEntry implements AnyHotEntry, SingleEntry {
public abstract sealed class HotEntry implements AnyHotEntry, SingleEntry permits BlobEntry, TreeEntry {
/**
* Creates a {@link BlobEntry} that lazily reads blob content from the given source.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/jp/ac/titech/c/se/stein/entry/SingleEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface SingleEntry extends Comparable<SingleEntry> {
* The kind of object an entry refers to.
*/
enum Type {
BLOB, TREE, LINK
blob, tree, link
}

/**
Expand Down Expand Up @@ -70,11 +70,11 @@ default boolean isBlob() {
*/
default Type getType() {
if (isTree()) {
return Type.TREE;
return Type.tree;
} else if (isLink()) {
return Type.LINK;
return Type.link;
} else {
return Type.BLOB;
return Type.blob;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/jp/ac/titech/c/se/stein/entry/TreeEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @see SourceTree
* @see NewTree
*/
public abstract class TreeEntry extends HotEntry {
public abstract sealed class TreeEntry extends HotEntry permits TreeEntry.SourceTree, TreeEntry.NewTree {
@Override
public int getMode() {
return FileMode.TREE.getBits();
Expand Down Expand Up @@ -53,7 +53,7 @@ public NewTree update(List<HotEntry> newChildren) {
* A Hot tree entry backed by an existing tree in a repository.
* The tree contents are lazily loaded on the first call to {@link #getEntries()}.
*/
public static class SourceTree extends TreeEntry {
public static final class SourceTree extends TreeEntry {
@Delegate(types = SingleEntry.class)
private final Entry entry;

Expand Down Expand Up @@ -106,7 +106,7 @@ public String toString() {
* On {@link #fold}, children are recursively folded and an empty tree
* (all children produce zero IDs) collapses to a zero-ID entry.</p>
*/
public static class NewTree extends TreeEntry {
public static final class NewTree extends TreeEntry {
@Getter
private final String name;
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ public AnyHotEntry rewriteBlobEntry(final BlobEntry entry, final Context c) {
}

private AnyHotEntry apply(AnyHotEntry input, List<BlobTranslator> rest, Context c) {
if (input instanceof BlobEntry) {
if (input instanceof BlobEntry blob) {
final BlobTranslator head = rest.get(0);
final List<BlobTranslator> tail = rest.subList(1, rest.size());
final AnyHotEntry result = head.rewriteBlobEntry((BlobEntry) input, c);
final AnyHotEntry result = head.rewriteBlobEntry(blob, c);
return tail.isEmpty() ? result : apply(result, tail, c);
}
if (input instanceof TreeEntry) {
final TreeEntry tree = (TreeEntry) input;
if (input instanceof TreeEntry tree) {
final List<HotEntry> newChildren = tree.getHotEntries().stream()
.flatMap(e -> apply(e, rest, c).stream())
.collect(Collectors.toList());
Expand Down
Loading
Loading