All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.dagere.peass.dependency.moduleinfo.ModuleInfoEditor Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
package de.dagere.peass.dependency.moduleinfo;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.modules.ModuleDeclaration;
import com.github.javaparser.ast.modules.ModuleRequiresDirective;

import de.dagere.peass.dependency.changesreading.JavaParserProvider;

/**
 * If a module-info exists, kieker needs to be added as required, since its used directly in the source code.
 * 
 * @author DaGeRe
 *
 */
public enum ModuleInfoEditor {
   ;

   public static void addKiekerRequires(final File moduleInfoFile) throws IOException {
      CompilationUnit unit = JavaParserProvider.parse(moduleInfoFile);
      ModuleDeclaration module = unit.getModule().get();

      addRequires(module, "kieker");
      addRequires(module, "kopeme.core"); // only needed until Kieker contains the DurationRecord

      Files.write(moduleInfoFile.toPath(), unit.toString().getBytes(StandardCharsets.UTF_8));
   }

   private static void addRequires(final ModuleDeclaration module, final String name) {
      ModuleRequiresDirective requirement = new ModuleRequiresDirective();
      requirement.setName(name);
      module.getDirectives().add(requirement);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy