Search in sources :

Example 1 with BuildMessage

use of org.jetbrains.jps.incremental.messages.BuildMessage in project intellij-community by JetBrains.

the class BuildMain method main.

public static void main(String[] args) throws Throwable {
    try {
        final long processStart = System.currentTimeMillis();
        final String startMessage = "Build process started. Classpath: " + System.getProperty("java.class.path");
        System.out.println(startMessage);
        LOG.info(startMessage);
        final String host = args[HOST_ARG];
        final int port = Integer.parseInt(args[PORT_ARG]);
        final UUID sessionId = UUID.fromString(args[SESSION_ID_ARG]);
        @SuppressWarnings("ConstantConditions") final File systemDir = new File(FileUtil.toCanonicalPath(args[SYSTEM_DIR_ARG]));
        Utils.setSystemRoot(systemDir);
        final long connectStart = System.currentTimeMillis();
        // IDEA-123132, let's try again
        for (int attempt = 0; attempt < 3; attempt++) {
            try {
                ourEventLoopGroup = new NioEventLoopGroup(1, SharedThreadPool.getInstance());
                break;
            } catch (IllegalStateException e) {
                if (attempt == 2) {
                    printErrorAndExit(host, port, e);
                    return;
                } else {
                    LOG.warn("Cannot create event loop, attempt #" + attempt, e);
                    try {
                        //noinspection BusyWait
                        Thread.sleep(10 * (attempt + 1));
                    } catch (InterruptedException ignored) {
                    }
                }
            }
        }
        final Bootstrap bootstrap = new Bootstrap().group(ourEventLoopGroup).channel(NioSocketChannel.class).handler(new ChannelInitializer() {

            @Override
            protected void initChannel(Channel channel) throws Exception {
                channel.pipeline().addLast(new ProtobufVarint32FrameDecoder(), new ProtobufDecoder(CmdlineRemoteProto.Message.getDefaultInstance()), new ProtobufVarint32LengthFieldPrepender(), new ProtobufEncoder(), new MyMessageHandler(sessionId));
            }
        }).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, true);
        final ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port)).awaitUninterruptibly();
        final boolean success = future.isSuccess();
        if (success) {
            LOG.info("Connection to IDE established in " + (System.currentTimeMillis() - connectStart) + " ms");
            final String projectPathToPreload = System.getProperty(PRELOAD_PROJECT_PATH, null);
            final String globalsPathToPreload = System.getProperty(PRELOAD_CONFIG_PATH, null);
            if (projectPathToPreload != null && globalsPathToPreload != null) {
                final PreloadedData data = new PreloadedData();
                ourPreloadedData = data;
                try {
                    // this will pre-load all FS optimizations
                    FileSystemUtil.getAttributes(projectPathToPreload);
                    final BuildRunner runner = new BuildRunner(new JpsModelLoaderImpl(projectPathToPreload, globalsPathToPreload, null));
                    data.setRunner(runner);
                    final File dataStorageRoot = Utils.getDataStorageRoot(projectPathToPreload);
                    final BuildFSState fsState = new BuildFSState(false);
                    final ProjectDescriptor pd = runner.load(new MessageHandler() {

                        @Override
                        public void processMessage(BuildMessage msg) {
                            data.addMessage(msg);
                        }
                    }, dataStorageRoot, fsState);
                    data.setProjectDescriptor(pd);
                    try {
                        final File fsStateFile = new File(dataStorageRoot, BuildSession.FS_STATE_FILE);
                        final DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(fsStateFile)));
                        try {
                            final int version = in.readInt();
                            if (version == BuildFSState.VERSION) {
                                final long savedOrdinal = in.readLong();
                                // must skip "has-work-to-do" flag
                                final boolean hasWorkToDo = in.readBoolean();
                                fsState.load(in, pd.getModel(), pd.getBuildRootIndex());
                                data.setFsEventOrdinal(savedOrdinal);
                                data.setHasHasWorkToDo(hasWorkToDo);
                            }
                        } finally {
                            in.close();
                        }
                    } catch (FileNotFoundException ignored) {
                    } catch (IOException e) {
                        LOG.info("Error pre-loading FS state", e);
                        fsState.clearAll();
                    }
                    // preloading target configurations
                    final BuildTargetsState targetsState = pd.getTargetsState();
                    for (BuildTarget<?> target : pd.getBuildTargetIndex().getAllTargets()) {
                        targetsState.getTargetConfiguration(target);
                    }
                    BuilderRegistry.getInstance();
                    LOG.info("Pre-loaded process ready in " + (System.currentTimeMillis() - processStart) + " ms");
                } catch (Throwable e) {
                    LOG.info("Failed to pre-load project " + projectPathToPreload, e);
                // just failed to preload the project, the situation will be handled later, when real build starts
                }
            } else if (projectPathToPreload != null || globalsPathToPreload != null) {
                LOG.info("Skipping project pre-loading step: both paths to project configuration files and path to global settings must be specified");
            }
            future.channel().writeAndFlush(CmdlineProtoUtil.toMessage(sessionId, CmdlineProtoUtil.createParamRequest()));
        } else {
            printErrorAndExit(host, port, future.cause());
        }
    } catch (Throwable e) {
        LOG.error(e);
        throw e;
    }
}
Also used : MessageHandler(org.jetbrains.jps.incremental.MessageHandler) InetSocketAddress(java.net.InetSocketAddress) ProtobufDecoder(io.netty.handler.codec.protobuf.ProtobufDecoder) ProtobufVarint32LengthFieldPrepender(io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender) BuildTargetsState(org.jetbrains.jps.incremental.storage.BuildTargetsState) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) Bootstrap(io.netty.bootstrap.Bootstrap) UUID(java.util.UUID) ProtobufVarint32FrameDecoder(io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ProtobufEncoder(io.netty.handler.codec.protobuf.ProtobufEncoder) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) BuildMessage(org.jetbrains.jps.incremental.messages.BuildMessage)

Example 2 with BuildMessage

use of org.jetbrains.jps.incremental.messages.BuildMessage in project android by JetBrains.

the class AndroidBuilderTest method testGeneratedSources.

public void testGeneratedSources() throws Exception {
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsModule module = setUpSimpleAndroidStructure(new String[] { "src", "gen" }, executor, null).getFirst();
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/R.java"), AndroidCommonUtils.AUTOGENERATED_JAVA_FILE_HEADER + "\n\n" + "package com.example.simple;\n" + "public class R {}");
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/copied_sources/com/example/simple/MyGeneratedClass.java");
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/R.java"));
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/MyGeneratedClass.java"));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_3");
    assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/copied_sources/com/example/simple/MyGeneratedClass.java");
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/MyGeneratedClass.java"), AndroidCommonUtils.AUTOGENERATED_JAVA_FILE_HEADER + "\n\n" + "package com.example.simple;\n" + "public class MyGeneratedClass {}");
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    assertCompiled(JavaBuilder.BUILDER_NAME);
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/MyGeneratedClass.java"), "package com.example.simple;\n" + "public class MyGeneratedClass {}");
    change(getProjectPath("src/com/example/simple/MyActivity.java"), "package com.example.simple;\n" + "import android.app.Activity;\n" + "import android.os.Bundle;\n" + "public class MyActivity extends Activity {\n" + "    public void onCreate(Bundle savedInstanceState) {\n" + "        super.onCreate(savedInstanceState);\n" + "        new MyGeneratedClass();" + "    }\n" + "}\n");
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_5");
    assertCompiled(JavaBuilder.BUILDER_NAME, "root/src/com/example/simple/MyActivity.java", "targets/java-production/module/android/copied_sources/com/example/simple/MyGeneratedClass.java");
    checkMakeUpToDate(executor);
    final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(myProject);
    final ProcessorConfigProfile profile = compilerConfig.getAnnotationProcessingProfile(module);
    profile.setEnabled(true);
    profile.setOutputRelativeToContentRoot(true);
    profile.setGeneratedSourcesDirectoryName("gen", false);
    final BuildResult result = makeAll();
    result.assertFailed();
    final List<BuildMessage> warnMessages = result.getMessages(BuildMessage.Kind.WARNING);
    boolean containsForciblyExcludedRootWarn = false;
    for (BuildMessage message : warnMessages) {
        if (message.getMessageText().endsWith("was forcibly excluded by the IDE, so custom generated files won't be compiled")) {
            containsForciblyExcludedRootWarn = true;
        }
    }
    assertTrue(containsForciblyExcludedRootWarn);
}
Also used : BuildMessage(org.jetbrains.jps.incremental.messages.BuildMessage) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) BuildResult(org.jetbrains.jps.builders.BuildResult) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile)

Example 3 with BuildMessage

use of org.jetbrains.jps.incremental.messages.BuildMessage in project intellij-community by JetBrains.

the class JpsMavenJavaBuildingTest method testCompileJava.

public void testCompileJava() throws IOException {
    File srcDir = PathManagerEx.findFileUnderProjectHome("plugins/maven/jps-plugin/testData/compiler/classpathTest", getClass());
    File workDir = FileUtil.createTempDirectory("mavenJavaBuild", null);
    FileUtil.copyDir(srcDir, workDir);
    addJdk("1.6");
    loadProject(workDir.getAbsolutePath());
    BuildResult result = doBuild(CompileScopeTestBuilder.rebuild().allModules());
    result.assertFailed();
    BuildMessage message = assertOneElement(result.getMessages(BuildMessage.Kind.ERROR));
    assertTrue(message.toString(), message.getMessageText().contains("Maven project configuration") && message.getMessageText().contains("isn't available."));
}
Also used : BuildMessage(org.jetbrains.jps.incremental.messages.BuildMessage) BuildResult(org.jetbrains.jps.builders.BuildResult) File(java.io.File)

Aggregations

BuildMessage (org.jetbrains.jps.incremental.messages.BuildMessage)3 BuildResult (org.jetbrains.jps.builders.BuildResult)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 ProtobufDecoder (io.netty.handler.codec.protobuf.ProtobufDecoder)1 ProtobufEncoder (io.netty.handler.codec.protobuf.ProtobufEncoder)1 ProtobufVarint32FrameDecoder (io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder)1 ProtobufVarint32LengthFieldPrepender (io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender)1 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 UUID (java.util.UUID)1 MessageHandler (org.jetbrains.jps.incremental.MessageHandler)1 BuildFSState (org.jetbrains.jps.incremental.fs.BuildFSState)1 BuildTargetsState (org.jetbrains.jps.incremental.storage.BuildTargetsState)1 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)1 ProcessorConfigProfile (org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile)1 JpsModule (org.jetbrains.jps.model.module.JpsModule)1