merge all into single repo

This commit is contained in:
fixminer
2020-04-06 20:40:32 +02:00
parent 9dcdb6aafc
commit 3c91dd7ea3
524 changed files with 1272301 additions and 1531 deletions
@@ -0,0 +1,28 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
* Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
*/
package com.github.gumtreediff.client;
public abstract class Client {
public Client(String[] args) {}
public abstract void run() throws Exception;
}
@@ -0,0 +1,62 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
* Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
*/
package com.github.gumtreediff.client;
import com.github.gumtreediff.gen.Registry;
public class Clients extends Registry<String, Client, Register> {
private static Clients registry;
public static Clients getInstance() {
if (registry == null)
registry = new Clients();
return registry;
}
protected String getName(Register annotation, Class<? extends Client> clazz) {
String name = annotation.name();
if (Register.no_value.equals(name))
name = clazz.getSimpleName().toLowerCase();
return name;
}
@Override
protected Entry newEntry(Class<? extends Client> clazz, Register annotation) {
String name = annotation.name().equals(Register.no_value)
? clazz.getSimpleName() : annotation.name();
return new Entry(name.toLowerCase(), clazz, defaultFactory(clazz, String[].class), annotation.priority()) {
@Override
protected boolean handle(String key) {
return id.equalsIgnoreCase(key);
}
final String description;
{
description = annotation.description();
}
@Override
public String toString() {
return String.format("%s: %s", id, description);
}
};
}
}
@@ -0,0 +1,97 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
* Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
*/
package com.github.gumtreediff.client;
import com.github.gumtreediff.gen.Generators;
import com.github.gumtreediff.matchers.Matchers;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collection;
@Register(description = "List things (matchers, generators, properties, ...)")
public class List extends Client {
public static final String SYNTAX = "Syntax: list " + Arrays.toString(Listable.values());
private final Listable item;
public List(String[] args) {
super(args);
if (args.length == 0)
throw new Option.OptionException(SYNTAX);
try {
Listable listable = Listable.valueOf(args[0].toUpperCase());
item = listable;
} catch (Exception e) {
throw new Option.OptionException(SYNTAX);
}
}
@Override
public void run() throws IOException {
item.print(System.out);
}
enum Listable {
MATCHERS {
@Override
Collection<?> list() {
return Matchers.getInstance().getEntries();
}
},
GENERATORS {
@Override
Collection<?> list() {
return Generators.getInstance().getEntries();
}
},
PROPERTIES {
@Override
Collection<?> list() {
return Arrays.asList(properties);
}
},
CLIENTS {
@Override
Collection<?> list() {
return Clients.getInstance().getEntries();
}
};
void print(PrintStream out) {
this.list().forEach(item -> out.println(item));
}
abstract Collection<?> list();
}
// This list is generated using (manually) list_properties (it is only an heuristic), some properties may be missing
public static final String[] properties = new String[] {
"gumtree.client.experimental (com.github.gumtreediff.client.Run)",
"gumtree.client.web.port (com.github.gumtreediff.client.diff.WebDiff)",
"gumtree.generator.experimental (com.github.gumtreediff.gen.TreeGeneratorRegistry)",
"line.separator (com.github.gumtreediff.io.IndentingXMLStreamWriter)",
"user.dir (com.github.gumtreediff.client.diff.AbstractDiffClient)"
};
}
@@ -0,0 +1,177 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
* Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
*/
package com.github.gumtreediff.client;
import java.io.PrintStream;
import java.util.ArrayList;
public abstract class Option {
final String description;
final String key;
final int paramCount;
public interface Context {
Option[] values();
static Option[] addValue(Option[] options, Option... newOptions) {
Option[] nopts = new Option[options.length + newOptions.length];
System.arraycopy(options, 0, nopts, 0, options.length);
System.arraycopy(newOptions, 0, nopts, options.length, newOptions.length);
return nopts;
}
}
@SuppressWarnings("serial")
public static class OptionException extends RuntimeException {
final Context context;
public OptionException(String msg, Context ctx) {
super(msg);
context = ctx;
}
public OptionException(String msg) {
this(msg, null);
}
public Context getContext() {
return context;
}
}
public Option(String key, String text) {
this(key, text, 0);
}
public Option(String key, String text, int params) {
this.key = key;
this.description = text;
this.paramCount = params;
}
public static String[] processCommandLine(String[] args, Context context) {
return processCommandLine(args, context.values(), context);
}
public static String[] processCommandLine(String[] args, Option[] availableOptions, Context ctx) {
ArrayList<String> todo = new ArrayList<>(args.length);
for (int i = 0; i < args.length; i++) {
String arg = args[i];
boolean found = false;
for (int j = 0; j < availableOptions.length && !found; j++) {
if (availableOptions[j].hasOption(arg)) {
int nbParams = availableOptions[j].paramCount;
String[] opts = new String[nbParams];
int currentParam = 0;
while (currentParam < nbParams) {
try {
opts[currentParam++] = args[++i];
} catch (ArrayIndexOutOfBoundsException e) {
throw new OptionException(String.format(
"Option '%s' expects more parameters, using null", arg), ctx);
}
}
availableOptions[j].process(arg, opts);
found = true;
}
}
if (!found) {
todo.add(arg);
}
}
String[] rest = new String[todo.size()];
todo.toArray(rest);
return rest;
}
protected boolean hasOption(String arg) {
return key.equals(arg);
}
protected abstract void process(String name, String[] args);
public String formatHelpText() {
return String.format("%s%s\t%s", key, (paramCount > 0 ? " <" + paramCount + ">" : ""), description);
}
public String toString() {
return key;
}
public static void displayOptions(PrintStream out, Context ctx) {
for (Option opt : ctx.values()) {
out.println(opt.formatHelpText());
}
}
public static class Help extends Option {
protected final Context context;
public Help(final Context ctx) {
super("--help", "Display help (this screen)");
context = ctx;
}
@Override
public void process(String name, String[] args) {
displayOptions(System.out, context);
System.exit(0);
}
}
public static class Text extends Option {
public Text(String text) {
super("", text);
}
@Override
public boolean hasOption(String opt) {
return false;
}
@Override
protected void process(String name, String[] args) {}
@Override
public String formatHelpText() {
return description;
}
}
public static class Verbose extends Option {
public static boolean verbose = false;
public Verbose() {
super("-v", "Verbose mode");
}
@Override
public boolean hasOption(String opt) {
return super.hasOption(opt) || opt.equals("--verbose");
}
@Override
protected void process(String name, String[] opts) {
verbose = true;
}
}
}
@@ -0,0 +1,47 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
* Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
*/
package com.github.gumtreediff.client;
import com.github.gumtreediff.gen.Registry;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Register {
String name() default no_value;
String description() default "";
int priority() default Registry.Priority.MEDIUM;
// FIXME currently unused, will be useful only for help purpose
Class<? extends Option.Context> options() default NoOption.class;
String no_value = "";
class NoOption implements Option.Context {
@Override
public Option[] values() {
return new Option[]{};
}
}
}
@@ -0,0 +1,141 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
* Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
*/
package com.github.gumtreediff.client;
import com.github.gumtreediff.gen.Generators;
import com.github.gumtreediff.gen.Registry;
import com.github.gumtreediff.gen.TreeGenerator;
import org.reflections.Reflections;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
public class Run {
public static class Options implements Option.Context {
@Override
public Option[] values() {
return new Option[]{
new Option("-c", "Set global property (-c property value). "
+ "Properties do not need to be prefixed by gumtree.", 2) {
@Override
protected void process(String name, String[] args) {
String key = args[0].startsWith("gumtree.") ? args[0] : "gumtree." + args[0];
System.setProperty(key, args[1]);
}
},
new Option.Verbose(),
new Help(this)
};
}
}
public static void initGenerators() {
Reflections reflections = new Reflections("com.github.gumtreediff.gen");
reflections.getSubTypesOf(TreeGenerator.class).forEach(
gen -> {
com.github.gumtreediff.gen.Register a =
gen.getAnnotation(com.github.gumtreediff.gen.Register.class);
if (a != null)
Generators.getInstance().install(gen, a);
});
}
public static void initClients() {
Reflections reflections = new Reflections("com.github.gumtreediff.client");
reflections.getSubTypesOf(Client.class).forEach(
cli -> {
com.github.gumtreediff.client.Register a =
cli.getAnnotation(com.github.gumtreediff.client.Register.class);
if (a != null)
Clients.getInstance().install(cli, a);
});
}
static {
initGenerators();
}
public static void startClient(String name, Registry.Factory<? extends Client> client, String[] args) {
try {
Client inst = client.newInstance(new Object[]{args});
try {
inst.run();
} catch (Exception e) {
System.err.printf("** Error while running client %s: %s\n", name, e);
}
} catch (InvocationTargetException e) {
System.err.printf("** Error while parsing option for %s:\n%s\n", name, e.getCause());
} catch (InstantiationException | IllegalAccessException e) {
System.err.printf("Can't instantiate client: '%s'\n%s\n", name, e);
e.printStackTrace();
}
}
public static void main(String[] args) {
Options opts = new Options();
args = Option.processCommandLine(args, opts);
initClients();
Registry.Factory<? extends Client> client;
if (args.length == 0) {
System.err.println("** No command given.");
displayHelp(System.err, opts);
} else if ((client = Clients.getInstance().getFactory(args[0])) == null) {
System.err.printf("** Unknown sub-command '%s'.\n", args[0]);
displayHelp(System.err, opts);
} else {
String[] a = new String[args.length - 1];
System.arraycopy(args, 1, a, 0, a.length);
startClient(args[0], client, a);
}
}
public static void displayHelp(PrintStream out, Option.Context ctx) {
out.println("Available Options:");
Option.displayOptions(out, ctx);
out.println("");
listCommand(out);
}
@SuppressWarnings("rawtypes")
public static void listCommand(PrintStream out) {
out.println("Available Commands:");
for (Registry.Entry cmd: Clients.getInstance().getEntries())
out.println("* " + cmd);
}
static class Help extends Option.Help {
public Help(Context ctx) {
super(ctx);
}
@Override
public void process(String name, String[] args) {
displayHelp(System.out, context);
System.exit(0);
}
}
}
@@ -0,0 +1,129 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
* Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
*/
package com.github.gumtreediff.client;
import com.github.gumtreediff.io.TreeIoUtils;
import com.github.gumtreediff.gen.Generators;
import com.github.gumtreediff.tree.TreeContext;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.Arrays;
@Register(name = "parse", description = "Parse file and dump result")
public class Serializer extends Client {
public static final String SYNTAX = "Syntax: parse [options] file ...";
static class Options implements Option.Context {
protected OutputFormat format = OutputFormat.JSON;
protected String output = null;
protected String[] files;
@Override
public Option[] values() {
return new Option[]{
new Option("-f", "Output format " + Arrays.toString(OutputFormat.values()), 1) {
@Override
protected void process(String name, String[] args) {
OutputFormat o = OutputFormat.valueOf(args[0].toUpperCase());
if (o != null)
format = o;
else
System.err.println("Invalid output type: " + args[0]);
}
},
new Option("-o", "Output filename (or directory if more than one file), defaults to stdout", 1) {
@Override
protected void process(String name, String[] args) {
}
}
};
}
}
enum OutputFormat {
JSON {
@Override
TreeIoUtils.TreeSerializer getSerializer(TreeContext ctx) {
return TreeIoUtils.toJson(ctx);
}
},
XML {
@Override
TreeIoUtils.TreeSerializer getSerializer(TreeContext ctx) {
return TreeIoUtils.toCompactXml(ctx);
}
},
FULLXML {
@Override
TreeIoUtils.TreeSerializer getSerializer(TreeContext ctx) {
return TreeIoUtils.toXml(ctx);
}
},
DOT {
@Override
TreeIoUtils.TreeSerializer getSerializer(TreeContext ctx) {
return TreeIoUtils.toDot(ctx);
}
},
LISP {
@Override
TreeIoUtils.TreeSerializer getSerializer(TreeContext ctx) {
return TreeIoUtils.toLisp(ctx);
}
};
abstract TreeIoUtils.TreeSerializer getSerializer(TreeContext ctx);
}
Options opts = new Options();
public Serializer(String[] args) {
super(args);
args = Option.processCommandLine(args, opts);
if (args.length == 0)
throw new Option.OptionException(SYNTAX);
opts.files = args;
}
@Override
public void run() throws IOException {
final boolean multiple = opts.files.length > 1;
if (multiple && opts.output != null)
Files.createDirectories(FileSystems.getDefault().getPath(opts.output));
for (String file : opts.files) {
try {
TreeContext tc = Generators.getInstance().getTree(file);
opts.format.getSerializer(tc).writeTo(opts.output == null
? System.out
: new FileOutputStream(opts.output));
} catch (Exception e) {
System.err.println(e);
}
}
}
}
@@ -0,0 +1,27 @@
pdf()
files <- dir(pattern="metrics.*csv")
s_script <- vector(mode="integer")
s_ins <- vector(mode="integer")
s_del <- vector(mode="integer")
s_up <- vector(mode="integer")
s_mov <- vector(mode="integer")
t_total <- vector(mode="integer")
for (file in files) {
d <- read.csv(file, header=T, sep=";")
length(d[[3]])
s_script <- cbind(s_script, d[[3]])
s_ins <- cbind(s_ins, d[[3]])
s_del <- cbind(s_del, d[[4]])
s_up <- cbind(s_up, d[[5]])
s_mov <- cbind(s_mov, d[[6]])
t_total <- cbind(t_total, d[[11]])
}
boxplot(s_script, main="Edit script size")
boxplot(s_ins, main="Insert actions")
boxplot(s_del, main="Delete actions")
boxplot(s_up, main="Update actions")
boxplot(s_mov, main="Move actions")
boxplot(t_total, main="Total time")
@@ -0,0 +1,25 @@
#!/bin/sh
#
# This file is part of GumTree.
#
# GumTree is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GumTree is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with GumTree. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
# Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
#
find . -name '*.java' | xargs grep -o 'System.getProperty.*'|
grep -v '^./samples' | grep -o 'fr/labri.gumtree.*'|
sed 's/System.getProperty("\([^"]*\)".*/\1/' | tr / . |
sed 's/\(.*\).java:\(.*\)/"\2 (\1)",/' | sort -u