mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
Created splitting project, implemented project finder
This commit is contained in:
parent
3f9dc023df
commit
47ec7fd28c
6 changed files with 225 additions and 0 deletions
6
splitting/.classpath
Normal file
6
splitting/.classpath
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
17
splitting/.project
Normal file
17
splitting/.project
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>splitting</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
11
splitting/.settings/org.eclipse.jdt.core.prefs
Normal file
11
splitting/.settings/org.eclipse.jdt.core.prefs
Normal file
|
@ -0,0 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
29
splitting/build.gradle
Normal file
29
splitting/build.gradle
Normal file
|
@ -0,0 +1,29 @@
|
|||
apply plugin: 'java'
|
||||
|
||||
def splitDir = file("$buildDir/splitting")
|
||||
|
||||
sourceSets.main.java.srcDirs = ['src']
|
||||
|
||||
def splittingPath = "$buildDir/splitting"
|
||||
def allHistoryFiles = file(splittingPath + "/all-files.txt")
|
||||
def allProjects = file(splittingPath + "/all-projects.txt")
|
||||
def unmappedPaths = file(splittingPath + "/unmapped-paths.txt")
|
||||
|
||||
task listFiles(type: Exec) {
|
||||
outputs.file allHistoryFiles
|
||||
workingDir '..'
|
||||
commandLine 'git', 'log', '--pretty=format:', '--name-only', '--diff-filter=A'
|
||||
doFirst {
|
||||
new File(allHistoryFiles.parent).mkdirs()
|
||||
standardOutput = new FileOutputStream(allHistoryFiles)
|
||||
}
|
||||
}
|
||||
|
||||
task findProjects(type: JavaExec) {
|
||||
dependsOn(sourceSets.main.runtimeClasspath, listFiles)
|
||||
inputs.file allHistoryFiles
|
||||
outputs.files allProjects, unmappedPaths
|
||||
classpath = sourceSets.main.runtimeClasspath.filter{it.exists()}
|
||||
main = "org.eclipse.xtext.splitting.FindProjects"
|
||||
args splittingPath
|
||||
}
|
0
splitting/settings.gradle
Normal file
0
splitting/settings.gradle
Normal file
162
splitting/src/org/eclipse/xtext/splitting/FindProjects.java
Normal file
162
splitting/src/org/eclipse/xtext/splitting/FindProjects.java
Normal file
|
@ -0,0 +1,162 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.splitting;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FindProjects {
|
||||
|
||||
public static final String ALL_FILES = "all-files.txt";
|
||||
public static final String ALL_PROJECTS = "all-projects.txt";
|
||||
public static final String UNMAPPED_PATHS = "unmapped-paths.txt";
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length != 1) {
|
||||
System.err.println("Expected file list as argument.");
|
||||
return;
|
||||
}
|
||||
String workingDir = args[0];
|
||||
try {
|
||||
final Directory root = new Directory(".", null);
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(workingDir + "/" + ALL_FILES))) {
|
||||
// Gather all paths in a directory structure
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] segments = line.split("/");
|
||||
DirectoryEntry current = root;
|
||||
for (int i = 0; i < segments.length; i++) {
|
||||
String segment = segments[i].replaceAll("\"|\\\\.", "");
|
||||
if (!segment.isEmpty() && current instanceof Directory) {
|
||||
Directory currentDir = (Directory) current;
|
||||
if (currentDir.entries.containsKey(segment))
|
||||
current = currentDir.entries.get(segment);
|
||||
else {
|
||||
DirectoryEntry newEntry;
|
||||
if (i == segments.length - 1)
|
||||
newEntry = new DirectoryEntry(segment, currentDir);
|
||||
else
|
||||
newEntry = new Directory(segment, currentDir);
|
||||
currentDir.entries.put(segment, newEntry);
|
||||
current = newEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find the projects and unmapped paths that are relevant for the repository history
|
||||
final List<Directory> projects = new ArrayList<>();
|
||||
final List<DirectoryEntry> otherPaths = new ArrayList<>();
|
||||
findProjects(root, projects, otherPaths, false);
|
||||
|
||||
// Write the collected projects into a file
|
||||
Collections.sort(projects);
|
||||
try (FileWriter writer = new FileWriter(workingDir + "/" + ALL_PROJECTS)) {
|
||||
for (Directory project : projects) {
|
||||
writer.write(project.toString());
|
||||
writer.write('\n');
|
||||
}
|
||||
}
|
||||
|
||||
// Write the unmapped paths into another file
|
||||
Collections.sort(otherPaths);
|
||||
try (FileWriter writer = new FileWriter(workingDir + "/" + UNMAPPED_PATHS)) {
|
||||
for (DirectoryEntry path : otherPaths) {
|
||||
writer.write(path.toString());
|
||||
writer.write('\n');
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean findProjects(Directory dir, List<Directory> projects, List<DirectoryEntry> otherPaths, boolean skipOtherPaths) {
|
||||
boolean containsProject = dir.parent != null && dir.entries.values().stream().anyMatch((e) -> e.name.equals(".project"));
|
||||
if (containsProject) {
|
||||
projects.add(dir);
|
||||
skipOtherPaths = true;
|
||||
}
|
||||
Set<Directory> subDirsWithProjects = new HashSet<>();
|
||||
for (DirectoryEntry entry : dir.entries.values()) {
|
||||
if (entry instanceof Directory) {
|
||||
Directory subDir = (Directory) entry;
|
||||
if (findProjects(subDir, projects, otherPaths, skipOtherPaths))
|
||||
subDirsWithProjects.add(subDir);
|
||||
}
|
||||
}
|
||||
if (!skipOtherPaths && !subDirsWithProjects.isEmpty()) {
|
||||
for (DirectoryEntry entry : dir.entries.values()) {
|
||||
if (!subDirsWithProjects.contains(entry))
|
||||
otherPaths.add(entry);
|
||||
}
|
||||
}
|
||||
return containsProject || !subDirsWithProjects.isEmpty();
|
||||
}
|
||||
|
||||
private static class DirectoryEntry implements Comparable<DirectoryEntry> {
|
||||
final String name;
|
||||
final Directory parent;
|
||||
|
||||
DirectoryEntry(String name, Directory parent) {
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Directory) {
|
||||
Directory other = (Directory) obj;
|
||||
return this.parent == other.parent && this.name.equals(other.name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (parent == null)
|
||||
return name.hashCode();
|
||||
else
|
||||
return parent.hashCode() * 7 + name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(DirectoryEntry other) {
|
||||
if (this.parent == other.parent)
|
||||
return this.name.compareTo(other.name);
|
||||
else
|
||||
return this.toString().compareTo(other.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (parent == null || parent.parent == null)
|
||||
return name;
|
||||
else
|
||||
return parent.toString() + "/" + name;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Directory extends DirectoryEntry {
|
||||
final Map<String, DirectoryEntry> entries = new HashMap<>();
|
||||
|
||||
Directory(String name, Directory parent) {
|
||||
super(name, parent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue