Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Apr 26, 2021
0 parents commit 5a0d356
Show file tree
Hide file tree
Showing 27 changed files with 2,165 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
*.java text
*.kt text
*.json text
*.asar -text
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Created by https://www.toptal.com/developers/gitignore/api/gradle
# Edit at https://www.toptal.com/developers/gitignore?templates=gradle

### Gradle ###
.gradle
build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### Gradle Patch ###
**/build/

# End of https://www.toptal.com/developers/gitignore/api/gradle

.idea
44 changes: 44 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
// for subproject configurations
java
`maven-publish`
signing
}

group = "com.anatawa12.asar4j"
version = "1.0-SNAPSHOT"

subprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
apply(plugin = "signing")

group = project(":").group
version = project(":").version

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.apache.commons:commons-compress:1.20")
testImplementation("com.google.guava:guava:30.1.1-jre")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

tasks.test {
useJUnitPlatform()
}

tasks.compileJava {
options.compilerArgs.add("-Xlint")
}
}
3 changes: 3 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
java
}
62 changes: 62 additions & 0 deletions common/src/main/java/com/anatawa12/asar4j/AsarDirectoryEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.anatawa12.asar4j;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

class AsarDirectoryEntry extends AsarEntry {
// if java.util.HashMap, this is mutable.
// if not, this must be immutable.
private Map<String, AsarEntry> entries;

AsarDirectoryEntry(String name, Map<String, AsarEntry> files) {
super(name);
entries = files;
}

@Override
public AsarEntryType getType() {
return AsarEntryType.DIRECTORY;
}

@Override
public Collection<AsarEntry> getChildren() throws IllegalStateException {
return Collections.unmodifiableCollection(entries.values());
}

@Override
public AsarEntry getChild(String name) throws IllegalStateException {
return entries.get(name);
}

@Override
public boolean isExecutable() {
throw new IllegalStateException("this is not FILE, but DIRECTORY");
}

@Override
public void setExecutable(boolean executable) {
throw new IllegalStateException("this is not FILE, but DIRECTORY");
}

void addChild(AsarEntry child) {
if (!child.getName().startsWith(getName())
|| child.getName().length() == getName().length()
|| child.getName().charAt(child.getName().length() - 1) != '/')
throw new IllegalArgumentException("the entry is not descendants of this");
String name = child.getName().substring(getName().length() + 1);
if (name.contains("/"))
throw new IllegalArgumentException("the entry is grandchildren");
entries.put(name, child);
}

@Override
protected AsarDirectoryEntry clone() {
AsarDirectoryEntry entry = (AsarDirectoryEntry) super.clone();
if (entries instanceof HashMap<?, ?>) {
entry.entries = new HashMap<>(entries);
}
return entry;
}
}
Loading

0 comments on commit 5a0d356

Please sign in to comment.