Skip to content

Commit

Permalink
changed the XML format on the db side
Browse files Browse the repository at this point in the history
  • Loading branch information
Cornul11 committed Jul 11, 2023
1 parent 8fb796f commit 29e4f57
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
import nl.tudelft.cornul11.thesis.corpus.file.JarInfoExtractor;
import nl.tudelft.cornul11.thesis.corpus.file.LibraryMatchInfo;
import nl.tudelft.cornul11.thesis.corpus.model.Signature;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.Xpp3DomWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.sql.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -178,15 +184,11 @@ public void insertPluginInfo(Model model, Plugin shadePlugin) {
ResultSet generatedKeys = pluginStatement.getGeneratedKeys();
if (generatedKeys.next()) {
int pluginId = generatedKeys.getInt(1);
Map<String, String> configValues = parsePluginConfig(shadePlugin);

PreparedStatement configStatement = connection.prepareStatement(insertPluginConfigQuery);
for (Map.Entry<String, String> entry : configValues.entrySet()) {
configStatement.setInt(1, pluginId);
configStatement.setString(2, entry.getKey());
configStatement.setString(3, entry.getValue());
configStatement.executeUpdate();
}
configStatement.setInt(1, pluginId);
configStatement.setString(2, serializeXpp3Dom((Xpp3Dom) shadePlugin.getConfiguration()));
configStatement.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
Expand Down Expand Up @@ -253,25 +255,44 @@ public Model retrievePluginInfo(String groupId, String artifactId, String versio
configStatement.setInt(1, pluginResultSet.getInt("id"));
ResultSet configResultSet = configStatement.executeQuery();

Map<String, String> configValues = new HashMap<>();
while (configResultSet.next()) {
configValues.put(configResultSet.getString("config_key"), configResultSet.getString("config_value"));
if (configResultSet.next()) {
shadePlugin.setConfiguration(deserializeXpp3Dom(configResultSet.getString("config")));
}
shadePlugin.setConfiguration(mapToXpp3Dom(configValues));

}
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
});
});

Build build;
if (model.getBuild() == null) {
build = new Build();
} else {
build = model.getBuild();
}

model.setPlugin(shadePlugin);
build.addPlugin(shadePlugin);
model.setBuild(build);

return model;
}


public String serializeXpp3Dom(Xpp3Dom dom) {
StringWriter writer = new StringWriter();
Xpp3DomWriter.write(new PrintWriter(writer), dom);
return writer.toString();
}

public Xpp3Dom deserializeXpp3Dom(String xml) throws Exception {
return Xpp3DomBuilder.build(new StringReader(xml));
}


public Xpp3Dom mapToXpp3Dom(Map<String, String> map) {
Xpp3Dom config = new Xpp3Dom("configuration");
for (Map.Entry<String, String> entry : map.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class OracleInformationComparator {
private final Logger logger = LoggerFactory.getLogger(OracleInformationComparator.class);
private final SignatureDAO signatureDAO;

public OracleInformationComparator(SignatureDAO signatureDAO) {
this.signatureDAO = signatureDAO;
}
Expand Down Expand Up @@ -70,9 +71,10 @@ private List<String> inferLibraries(Path jarPath) {
}

private Model getModelByJarPath(Path jarPath) {

return null;
}

public String getResults() {
return null;
}
}

0 comments on commit 29e4f57

Please sign in to comment.