Skip to content
Open
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
6 changes: 6 additions & 0 deletions java-lib/modelset-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
<version>1.15.0</version>
</dependency>


<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.5.2</version>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package modelset.database;

import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;

import mar.validation.IFileInfo;
import mar.validation.IFileProvider;
import modelset.process.DuplicationDatabase;

public class DuplicationAdapterProvider implements IFileProvider {

private IFileProvider provider;
private DuplicationDatabase dupDb;

public DuplicationAdapterProvider(IFileProvider provider, DuplicationDatabase dupDb) {
this.provider = provider;
this.dupDb = dupDb;
}

@Override
public @Nonnull List<? extends IFileInfo> getLocalFiles() {
List<? extends IFileInfo> files = provider.getLocalFiles();
return files.stream().filter(f -> {
try {
return dupDb.isGroupRepresentive(f.getModelId());
} catch (SQLException e) {
throw new IllegalStateException(e);
}
}).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package modelset.database;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;

import mar.validation.IFileInfo;
import mar.validation.IFileProvider;

public class FilterAdapterFileProvider implements IFileProvider {

private IFileProvider provider;
private Predicate<IFileInfo> predicate;

public FilterAdapterFileProvider(IFileProvider provider, Predicate<IFileInfo> predicate) {
this.provider = provider;
this.predicate = predicate;
}

@Override
public @Nonnull List<? extends IFileInfo> getLocalFiles() {
List<? extends IFileInfo> files = provider.getLocalFiles();
return files.stream().filter(this.predicate).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package modelset.database;

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;

import mar.validation.AnalysisDB;
import mar.validation.AnalysisDB.Model;
import mar.validation.IFileInfo;
import mar.validation.IFileProvider;

public class MarAnalysisFileProvider implements IFileProvider {

private List<PlainFileInfo> files;

public MarAnalysisFileProvider(File db, File repoRoot, String type) throws SQLException, IOException {
if (! db.exists())
throw new IllegalArgumentException("File " + db + " does not exist");

try (AnalysisDB analysis = new AnalysisDB(db)) {
this.files = new ArrayList<PlainFileInfo>();
for (Model m : analysis.getValidModels(f -> f)) {
files.add(new PlainFileInfo(m.getId(), m.getRelativePath().toString(), repoRoot));
}
}
}

@Override
public @Nonnull List<? extends IFileInfo> getLocalFiles() {
return files;
}

public static boolean isMarDb(File f) throws SQLException {
try(Connection connection = DriverManager.getConnection(AnalysisDB.getConnectionString(f))) {
DatabaseMetaData dmd = connection.getMetaData();
ResultSet rs = dmd.getTables(null, null, "models", new String[] { "TABLE" });
ResultSet rs2 = dmd.getTables(null, null, "stats", new String[] { "TABLE" });
return rs.next() && rs2.next();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package modelset.database;

import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;

import mar.ingestion.CrawlerDB;
import mar.ingestion.IngestedModel;
import mar.validation.IFileProvider;

public class MarCrawlerFileProvider implements IFileProvider {

private List<PlainFileInfo> files;

public MarCrawlerFileProvider(File db, File repoRoot, String type) throws SQLException {
CrawlerDB crawlerDb = new CrawlerDB(type, "github", repoRoot.getAbsolutePath(), db);
this.files = new ArrayList<PlainFileInfo>();
for (IngestedModel m : crawlerDb.getModels()) {
files.add(new PlainFileInfo(m.getModelId(), m.getRelativePath(), repoRoot));
}
}

@Override
public @Nonnull List<? extends PlainFileInfo> getLocalFiles() {
return files;
}

public static boolean isCrawlerDb(File f) throws SQLException {
try(Connection connection = DriverManager.getConnection(CrawlerDB.getConnectionString(f))) {
DatabaseMetaData dmd = connection.getMetaData();
ResultSet rs = dmd.getTables(null, null, "data", new String[] { "TABLE" });
ResultSet rs2 = dmd.getTables(null, null, "repo_info", new String[] { "TABLE" });
return rs.next() && rs2.next();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package modelset.database;

import java.util.List;

import javax.annotation.Nonnull;

import mar.validation.IFileInfo;
import mar.validation.IFileProvider;

public class MaxModelsFileProvider implements IFileProvider {

private IFileProvider provider;
private int size;

public MaxModelsFileProvider(IFileProvider provider, int size) {
this.provider = provider;
this.size = size;
}

@Override
public @Nonnull List<? extends IFileInfo> getLocalFiles() {
return provider.getLocalFiles().subList(0, size);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package modelset.database;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;

import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;

import mar.modelling.loader.ILoader;
import mar.validation.IFileInfo;
import mar.validation.IFileProvider;

public class MinSizeAdapterProvider implements IFileProvider {

private IFileProvider provider;
private ILoader loader;
private int minSize;

public MinSizeAdapterProvider(IFileProvider provider, int minSize, ILoader loader) {
this.provider = provider;
this.loader = loader;
this.minSize = minSize;
}

@Override
public @Nonnull List<? extends IFileInfo> getLocalFiles() {
List<? extends IFileInfo> files = provider.getLocalFiles();
return files.stream().filter(f -> {
try {
Resource r = loader.toEMF(f.getFullFile());
boolean b = hasEnoughElements(r);
r.unload();
return b;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}).collect(Collectors.toList());
}

private boolean hasEnoughElements(Resource r) {
int count = 0;
TreeIterator<EObject> it = r.getAllContents();
while (it.hasNext()) {
count++;
if (count > minSize)
return true;
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package modelset.process;
package modelset.database;

import java.io.File;

Expand Down Expand Up @@ -40,4 +40,8 @@ public ModelSetFileInfo(String id, String filename, File repoRoot, ParsedMetadat
public ParsedMetadata getMetadata() {
return metadata;
}

public String getCategory() {
return metadata.getValues("category").get(0);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package modelset.process;
package modelset.database;

import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand All @@ -11,7 +12,6 @@

import javax.annotation.Nonnull;

import mar.validation.IFileInfo;
import mar.validation.IFileProvider;
import modelset.metadata.AnnotationsValidator;
import modelset.metadata.AnnotationsValidator.ParsedMetadata;
Expand Down Expand Up @@ -50,4 +50,12 @@ private static String getConnectionString(File file) {
return "jdbc:sqlite:" + file.getAbsolutePath();
}

public static boolean isModelSetDb(File f) throws SQLException {
try(Connection connection = DriverManager.getConnection(getConnectionString(f))) {
DatabaseMetaData dmd = connection.getMetaData();
ResultSet rs = dmd.getTables(null, null, "metadata", new String[] { "TABLE" });
ResultSet rs2 = dmd.getTables(null, null, "repositories", new String[] { "TABLE" });
return rs.next() && rs2.next();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package modelset.database;

import java.io.File;

import javax.annotation.Nonnull;

import mar.validation.IFileInfo;

public class PlainFileInfo implements IFileInfo {

private String id;
private String filename;
private File repoRoot;

public PlainFileInfo(String id, String filename, File repoRoot) {
this.id = id;
this.filename = filename;
this.repoRoot = repoRoot;
}

@Override
public @Nonnull File getFullFile() {
return new File(repoRoot.getAbsolutePath() + File.separator + filename);
}

@Override
public @Nonnull String getModelId() {
return id;
}

@Override
public @Nonnull File getRelativeFile() {
return new File(filename);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.List;
import java.util.stream.Collectors;

import modelset.process.ModelSetFileInfo;
import modelset.process.ModelSetFileProvider;
import modelset.database.ModelSetFileInfo;
import modelset.database.ModelSetFileProvider;

public class ModelSetDB {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.eclipse.emf.ecore.resource.Resource;

import mar.indexer.common.configuration.ModelLoader;
import modelset.database.ModelSetFileInfo;
import modelset.metadata.AnnotationsValidator.ParsedMetadata;
import modelset.process.ModelSetFileInfo;

public class ModelSetModel {

Expand Down
Loading